第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何使用動態(tài)名稱導(dǎo)出變量

如何使用動態(tài)名稱導(dǎo)出變量

qq_笑_17 2021-05-03 10:29:40
我在nuxt.js中有一個(gè)components文件夾/components/atoms/在該文件夾中,我可以index.js動態(tài)導(dǎo)出所有組件const req = require.context('./', true, /\.vue$/)const components = {}req.keys().forEach(fileName => {  const componentName = fileName.replace(/^.+\/([^/]+)\.vue/, '$1')  components[componentName] = req(fileName).default})export const { ButtonStyled, TextLead, InputSearch } = components所以我可以隨心所欲地導(dǎo)入import { ButtonStyled } from "@/components/atoms"問題是我正在定義要靜態(tài)導(dǎo)出,固定的變量,因此對于每個(gè)創(chuàng)建的組件,我需要手動添加另一個(gè)變量我需要?jiǎng)討B(tài)導(dǎo)出變量名例子:DynamicCreation = ['ButtonStyled', 'TextLead', 'InputSearch']export const { DynamicCreation } = components // output -> export const { ButtonStyled, TextLead,InputSearch  } = components我需要導(dǎo)出已經(jīng)非結(jié)構(gòu)化變量的名稱注意:我無法使用此文件,export default components因?yàn)槲覠o法像這樣導(dǎo)入import { ButtonStyled } from "@/components/atoms"
查看完整描述

3 回答

?
慕桂英4014372

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊

您可以通過這種方式進(jìn)行操作,檢查是否需要什么。


創(chuàng)建一個(gè)文件以導(dǎo)入組件的組合:allComponents.js


export default {

 componentOne: require('./passToOneComponent.js');

 componentTwo: require('./passToOneComponent.js');

 componentThree: require('./passToOneComponent.js');

}

在index.js中之后,導(dǎo)出具有您想要的名稱的allComponents.js:


export {default as SomeName } from 'allComponents.js';

因此,在最終文件中,您可以執(zhí)行以下操作:


import { SomeName } from 'index.js';


SomeName.componentOne();


查看完整回答
反對 回復(fù) 2021-05-13
?
慕村225694

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊

我創(chuàng)建了一個(gè)庫進(jìn)行這種類型的導(dǎo)出,任何想要的人都可以通過安裝 npm

我創(chuàng)建了一個(gè)Webpack插件,該插件可以從組件進(jìn)行命名導(dǎo)出,也許這可以幫助其他人

Weback插件-named-exports


查看完整回答
反對 回復(fù) 2021-05-13
  • 3 回答
  • 0 關(guān)注
  • 321 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號