如何才能让vue-router的懒加载使用动态命名
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利
以下代码是可以执行的
export default new Router({
routes: [
{
path: '/',
component: (resolve) => {
require.ensure([], () => {
return resolve(require('../A.vue'))
}, 'dist/js/cm/testA')
}
},
{
path: '/b',
component: (resolve) => {
require.ensure([], () => {
return resolve(require('../B.vue'))
}, 'dist/js/cm/testB')
}
}
]
});
为什么下面这段代码,进行webpack打包的时候就不行了尼?
const getRe = (resolve,name,parts = 'page') => {
var path = '../' + parts + '/' + name + '.vue';
require.ensure([], () => {
resolve(require(path));
},'dist/js/cm/' + name);
};
export default new Router({
routes: [
{
path: '/',
component: (resolve) => {
require.ensure([], () => {
return resolve(require('../com/A.vue'))
}, 'dist/js/cm/testA')
}
},
{
path: '/b',
component: (resolve) => {
return getRe(resolve,'Readme');
}
}
]
});