问题:vue打包项目发现打包结果太大了,vuex太大了
解决方案:按组件加载vuex
function a(){
//因为a有install,所以这里不会被执行
}
//vue引入文件import,require.ensure
//Vue.use(a),如果参数a有install属性就执行install,如果没有就执行a本身
a.install = function(vue){
vue.mixin({
created:function(){
//有没有需要异步加载的vuex-》import()方法从module里面引入该js-》注册到vuex上
if(this.$options.isVuex){
var _name = this.$options.name;
import("./store/module/"+_name).then(res)=>{
this.$stroe.registerModule(this.$options.name,res.default);
}
}
}
})
}
Vue.use(a);
博客指出Vue打包项目时存在打包结果和Vuex过大的问题,针对此问题给出解决方案,即按组件加载Vuex,以此优化打包结果。
1906

被折叠的 条评论
为什么被折叠?



