这里有一份Vue动态组件解决方案,你想看吗?

千言万语敌不过一张动图 git

动态组件.gif
都是有身份的程序猿,以码会友:

const DynamicComponent = {
  props: {
    componentName: {
      type: String,
      required: true
    },
    componentProps: {
      type: Object,
      default: () => {
      }
    },
    styles: {
      type: Object,
      default: () => {
      }
    }
  },
  render(createElem) {
    return createElem(this.componentName, {
      props: this.componentProps
    })
  }
}
export default DynamicComponent;

复制代码

使用的示例:github

<DynamicComponent v-for="(item, index) in componentsArray"
                        :key="index"
                        :componentName="item.component"
                        :componentProps="item.props"></DynamicComponent>
复制代码

就酱子。动态的往数据里面放数据便可bash

\color{red}{注意:须要动态加载的组件都须要使用 Vue.component() 注册,否则会报组件没有注册的错误!}

github.com/GaoGersy/Dy…微信

点个赞再走吧ui

这篇文章若是能拿下100个喜欢我就去买一块荣耀Magic手表奖励本身,说到作到!您的赞是我为国家GDP作贡献的原动力!this

关注微信公众号有惊喜哟,关注就送Vue从入门到放弃全套视频教程spa

关注就送Vue从入门到放弃全套视频教程
相关文章
相关标签/搜索