你可以尝试这样的方法:
new Vue({
el: '#app',
data () {
return {
i: 0, // set i to track the tab index
model: 'tab-2',
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
}
},
methods: {
changeTab(){
//update the index and model
this.i = (this.i + 1) % 3
this.model = `tab-${this.i+1}`
alert("Changing tab")
}
}
})
CodePen Example
.