动态引入组件
data: function () {
return {
component:null
}
},
init:(){
var componentname = “”;
if (this.sysname !== null && this.sysname !== ‘’ && this.sysname !== undefined && this.sysname.length>5 && this.sysname.indexOf(" ")==-1) {
//检查下要引入的组件对象是否存在,可以trycatch ,否则this.component 引入不存在的vue,页面会报错
try{
require(‘@/views/login/’+this.sysname + ‘.vue’);
this.component = () => import(‘@/views/login/’+this.sysname + ‘.vue’);
}.catch(error => {
console.log(error)
this.component = () => import(‘@/views/login/login.vue’);
}
}
}