vue 构造函数的 add 方法

import Vue from "vue";

new Vue({
    el : "#mybox",
    data : {
        a : 100
    },
    methods : {
        add : function(){
            this.a ++;
        }
    }
});

特别注意,add方法必须用function来定义,不能用()=>{箭头函数} 。 因为箭头函数里面的this指向类而不是实例。

原文地址:https://www.cnblogs.com/caoleyun/p/12691907.html