我在nuxt.js中有一个components文件夹
/components/atoms/
在该文件夹中,我可以index.js动态导出所有组件
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
所以我可以随心所欲地导入
import { ButtonStyled } from "@/components/atoms"
问题是我正在定义要静态导出,固定的变量,因此对于每个创建的组件,我需要手动添加另一个变量
我需要动态导出变量名
例子:
DynamicCreation = ['ButtonStyled', 'TextLead', 'InputSearch']
export const { DynamicCreation } = components
// output -> export const { ButtonStyled, TextLead,InputSearch } = components
我需要导出已经非结构化变量的名称
注意:我无法使用此文件,export default components因为我无法像这样导入import { ButtonStyled } from "@/components/atoms"
慕桂英4014372
慕村225694
相关分类