when you switch to tab-2 and set its color to red
and then switch back to tab-1, the value of color does not disappear
code is as follows: you can also click here to view
<div id="app">
<ul>
<li :class="`tab${item}`"
v-for="item in tabs"
v-if="tabIndex === item">tab-{{item}}</li>
</ul>
<button @click="switchTab">switch</button>
</div>
<script>
new Vue({
el: "-sharpapp",
data: {
tabs: [1, 2],
tabIndex: 1
},
methods: {
switchTab () {
this.tabIndex = this.tabIndex === 1 ? 2 : 1
this.$nextTick(() => {
if (this.tabIndex === 2) {
document.querySelector(".tab2").style.color = "red"
}
})
}
}
})
</script>