123456789101112131415161718 |
- export const registerGlobalAsyncComponents = (Vue) => {
- const context = require.context('@/template', true, /Sly[A-Za-z]+\.vue$/);
- context.keys().forEach(path => {
- const [_, name, file] = path.split('/'); // 根据路径获取组件名称
- if (name.indexOf('Sly') === 0) {
- const fileName = file ? file.split('.vue')[0] : '';
- const component = context(path)
- const ctrl = component.default || component
- // console.log("file.split('.vue') =" , ctrl.name ,file.split('.vue'))
- const a = ctrl.name || fileName || name // 如组件内部未定义组件名称,则取文件夹名称为组件名称
- const b = ctrl
- if (a === name) {
- // 注册组件(和文件夹同名才注册,类似于index)
- Vue.component(a, b)
- }
- }
- })
- }
|