Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

element tab组件使用Tabs的label slot不能及时动态更新

elementUI 的bug,tab组件使用Tabs的label slot不能及时动态更新。试过了Vue.set方法,forceUpdate(),都没有效果
image

源代码:

<el-tabs ref="tabs" v-model="activeName" type="border-card" @tab-click="handleClick">  
 <template v-for="item in tabs">  
     <el-tab-pane :key="item.name"  
     :name="item.name">  
         <span slot="label">{{ item.label }}<el-badge :value="item.count"></el-badge>
         </span>  
         <keep-alive> 
            <component 
                v-if="activeName === item.name"  
                v-bind:is="item.currentComponent"  
                @relatedRiskFuc="relatedRiskFuc"  
            >
            </component>  
         </keep-alive> 
     </el-tab-pane> 
 </template>
 </el-tabs>

github上也看到这个issue
Tabs的label slot不能及时动态更新 #2934

有没有遇到过这个问题的 ,如何解决的?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

已解决
this.$refs.tabs.$refs.nav.$forceUpdate()

relatedRiskFuc(val) {  
  const _this = this  
  for(let i = 0; i< this.tabs.length; i++) {  
    if(this.tabs[i].name === val.name) {  
      _this.$set(_this.tabs[i], 'count', val.tableData.length)  
      _this.$set(_this.tabs[i], 'asset_list', val.tableData)  
    }  
    _this.$set(_this.tabs, i, _this.tabs[i])  
    this.$refs.tabs.$refs.nav.$forceUpdate()  
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share

1.2m questions

2.1m answers

5 comments

56.5k users

...