vue 动态组件


1.动态组件:使用:is在不同组件之间进行动态切换

        让多个组件使用同一个挂载点,并动态切换,这就是动态组件。通过 Vue 的 <component> 元素加一个特殊的 :is 特性来实现。

2.完整代码

   动态标签页

<el-tabs v-model="editableTabsValue" type="card" class="recordinfor" style="background: #EFF2F1">
  <el-tab-pane v-for="(item) in editableTabs" :key="item.name" :label="item.title" :name="item.name">
    <component :is=item.content></component>
  </el-tab-pane>
</el-tabs>
   methods: {
      addTab (targetName) {
        let newTabName = ++this.tabIndex + '';
        this.editableTabsValue = newTabName;
        if (targetName === '基本信息') {
          this.show = true
        } else {
          this.show = false
        }
      },
    },
    mounted () {
        this.addTab(name)
    },

 

  import recordSite from './recordSite.vue'
  import recordEquipment from './recordEquipment.vue'
  import recordPerson from './recordPerson.vue'
  import recordSchool from './recordSchool.vue'
  import recordVehicle from './recordVehicle.vue'
  import recordLine from './recordLine.vue'   
   //声明组件
    components: {
      recordSite,
      recordEquipment,
      recordPerson ,
      recordSchool ,
      recordVehicle ,
      recordLine
    }
     //数据
        editableTabs: [{
          title: '考试场地信息',
          name: '1',
          content: 'recordSite'
        }, {
          title: '考试设备信息',
          name: '2',
          content: 'recordEquipment'
        }, {
          title: '考试员信息',
          name: '3',
          content: 'recordPerson'
        }, {
          title: '驾校信息',
          name: '4',
          content: 'recordSchool'
        }, {
          title: '考试车辆信息',
          name: '5',
          content: 'recordVehicle'
        }, {
          title: '考试线路',
          name: '6',
          content: 'recordLine'
        }],

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值