美文网首页
Vue中动态注入组件

Vue中动态注入组件

作者: 叶小七的真命天子 | 来源:发表于2019-12-03 15:37 被阅读0次

源自https://juejin.im/post/5de1d7d25188252112798118

Mark留存

<template>
  <div class="home">
    <component :is="item.component" v-for="(item ,index) in componentList" :info="item" :key="index" />
  </div>
</template>
computed: {
      componentList() {
        let { list } = this
       return list.map(item => {
          item.component = () => {
            return new Promise((resolve, reject) => {
             import(`@/components/${item.type}`).then(res => {
                resolve(res)
              }).catch(() => {
                resolve(import('@/components/Error'))
              })
            })
          }
          return item
        })
      }
    }

相关文章

网友评论

      本文标题:Vue中动态注入组件

      本文链接:https://www.haomeiwen.com/subject/jfgcgctx.html