vue require.context()动态文件引入
作者:互联网
require.context()
参数: 1、文件路径;
2、是否匹配子级文件(true,false);
3、正则,匹配的规则
demo:
const requireComponent = require.context('.', false, /\.vue$/); const install = (Vue) => { if (install.installed) return; install.installed; requireComponent.keys().forEach(fileName => { const config = requireComponent(fileName); const componentName = config.default.name; Vue.component(componentName, config.default || config); }) } if (typeof window !== 'undefined' && window.Vue) { install(window.Vue); } export default { install }
标签:requireComponent,Vue,const,context,require,window,vue,install,config 来源: https://www.cnblogs.com/houBlogs/p/15151691.html