通过v-if去控制tabs的pane显示和隐藏,会赞成数据无法保留,因为v-if会销毁组件,再重新创建。
我这里是通过设置选项卡的显示和隐藏(控制display)来做到的
// watch监听
watch: {
'ruleForm.isbrand' : { // 监听ruleForm的isbrand(是否品牌)被选中了
handler (newVal, oldVal) {
this.showTabPane(this.ruleForm.isbrand, 'tab-brand') // tab-brand是id名字,自己去html中查看tabs选项卡的dom节点id名
},
immediate: true
},
'ruleForm.isspecification' : {
handler (newVal, oldVal) {
this.showTabPane(this.ruleForm.isspecification, 'tab-spec')
},
immediate: true
}
}
// mehods里面定义showTabPane方法
showTabPane (control, pane) {
let dom = '';
this.$nextTick(() => {
dom = document.getElementById(pane)
if (control == 1) {
dom.style.display &