How to fire an event when v-model changes?

后端 未结 5 2143
滥情空心
滥情空心 2020-12-13 02:03

I\'m trying to fire the foo() function with the @click but as you can see, need press the radio button two times to fire the event correctly . Only

5条回答
  •  难免孤独
    2020-12-13 02:38

    You can actually simplify this by removing the v-on directives:

    
    

    And use the watch method to listen for the change:

    new Vue ({
        el: "#app",
        data: {
            cases: [
                { name: 'case A', status: '1' },
                { name: 'case B', status: '0' },
                { name: 'case C', status: '1' }
            ],
            activeCases: [],
            srStatus: ''
        },
        watch: {
            srStatus: function(val, oldVal) {
                for (var i = 0; i < this.cases.length; i++) {
                    if (this.cases[i].status == val) {
                        this.activeCases.push(this.cases[i]);
                        alert("Fired! " + val);
                    }
                }
            }
        }
    });
    

提交回复
热议问题