需求: 是根据不同的表格数据显示不同的tab选项卡,让其他的不显示
<template>
<el-tabs v-model="activeName" @tab-click="handleClick" ref="tabs">
<el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>
<el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
<el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
<el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
</el-tabs>
</template>
<script>
export default {
data() {
return {
activeName: 'second'
};
},
methods: {
handleClick(tab, event) {
console.log(tab, event);
},
hideTabs() {
//这个方法是把tab栏全部隐藏
//this.$refs.tabs.$children[0].$el.style.display = 'none';
//必须加this.$nextTick这个属性要不然就出不来
this.$nextTick(() => {
this.$refs.tabs.$children[0].$refs.tabs[2].style.display="none";
})
}
},
mounted () {
this.hideTabs();
}
}
</script>
注意:
开始时只用了 this.$refs.tabs.$children[0].$refs.tabs[2].style.display="none";
结果一直失败,必须放在this.$nextTick中才起作用