Vue 动态渲染组件

2020-05-25  本文已影响0人  1994陈

方法一:

 <el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab" @tab-click="editTab" class="indexTabs">
           <el-tab-pane v-for='item in tabList' :key='item.name' :label="item.title" :name='item.name'>
                 <keep-alive> 
                  <component :is='currentTabComponent' :name='index' ref='customerInfo' :customerData='customerData'></component>
                 </keep-alive>
           </el-tab-pane>  
         </el-tabs> 

<keep-alive> - 组件切换保留数据

方法二:

 <el-tab-pane v-for='item in tabList' :key='item.name' :label="item.title" :name='item.name'>
                 <keep-alive>
                 <tab-component :index='index' :name='index' ref='customerInfo'>
                 </tab-component>  
                 </keep-alive>
           </el-tab-pane>  
   //组件渲染
        renderComp(_activeNum){
            let _self=this,_comp;
             if(_self.tabsParams){
                _comp=_self.match[_activeNum].component
             }else{
                _comp=_self.tabList[_activeNum].content
             }
          
              var tabCompnent= Vue.component('tab-component',{
                  render:function(h){
                  return h(_comp)
             }
             });
                 console.log(this.$refs.customerInfo)  //获取子组件
             },
上一篇 下一篇

猜你喜欢

热点阅读