动态引入 某文件夹下所有vue组件的方法
引入vueconst context = require.context('./', true, /\.vue$/);const install = (Vue) => {context.keys().forEach((key) => {const component = context(key).default;Vue.component(component.name, compone
·
引入vue
const context = require.context('./', true, /\.vue$/);
const install = (Vue) => {
context.keys().forEach((key) => {
const component = context(key).default;
Vue.component(component.name, component);
});
};
或者
const context = require.context("./", true, /\.vue$/);
const cmps = {};
context.keys().forEach((key) => {
const component = context(key).default;
cmps[component.name] = component;
});
components: {
...cmps,
},
引入css 等
const context = require.context('./', true, /\.scss$/);
context.keys().forEach((key) => {
// eslint-disable-next-line
console.log(context(key));//本行代码看似无用,却是样式文件能够成功引入的关键
});
更多推荐
已为社区贡献5条内容
所有评论(0)