vue.js v-model里的value监测变化并触发函数,我这样有什么问题吗

new Vue({
    el:'html',
    data(){
       return{
       ...
       needreceipt:true,
       ...
       }
    },
     watch:{
        'needreceipt':function (val) {
            console.log(val);
        }
    },
    ...
})
<input id="fapiao" class="check" name="style" type="checkbox" v-model="needreceipt">
<label for="fapiao" class="trigger"><i></i>{{needreceipt}}</label>

label中的内容正确变化,为什么watch里的function不会执行

阅读 11.7k
3 个回答

copy 你的代码,试过试可以执行的,没问题。

Codepen

这样试试把引号去掉

 watch:{
         needreceipt:function (val) {
            console.log(val);
        }
    },

把引号去了

needreceipt:function (val) {
            console.log(val);
        }
推荐问题