Vue.js - Add class to clicked button

后端 未结 1 567
借酒劲吻你
借酒劲吻你 2021-01-25 14:26

The following code is meant to display several products displayed by brand. when you press the brand\'s button it will display its products. this is working fine however I\'ve a

1条回答
  •  时光说笑
    2021-01-25 14:58

    Try to add another data object property called currentIndex and update it to the clicked button index :

    // DATA
    data() {
        return {
             currentIndex:-1,
            isActive: false,
               ...
    

    inside the template bind the class as follows :class='{buttonActive : (index==currentIndex) }':

    methods :

        changeBrand(index) {
            this.object = this.brand[index].products;
            this.currentIndex=index;
    
    
        }
    

    0 讨论(0)
提交回复
热议问题