自定义component根据输入的不同字符串,给component绑定的变量赋值不同的组件变量名
原做法:
import gpf from ‘./gpf.vue’
const str = ‘gpf’; // 模仿传入
this.component = eval( str)
原做法问题:
eval(‘gpf’)找不到gpf这个变量,显示 not defined
解决方法:
const str = ‘gpf’;
const gpf=() => import(’./gpf.vue’),
const currentComponent= eval(‘gpf’)
console.log(currentComponent)
this.component = currentComponent
更好的解决方法:
import gpf from ‘./gpf.vue’
const str = ‘gpf’; // 模仿传入
const allcomponent = {gpf}
this.component = allcomponent[str]
参考:https://blog.csdn.net/weixin_38659265/article/details/103568077