示例
html:
<div id="app">
<button v-on:click="show1">Button1</button>
<button @click="show2">Button2</button>
<button @click="show3">Button3</button>
<div id="box">{{msg}}</div>
</div>
JS:
let vm = new Vue({
el: "#app",
data: {
b1: false,
msg: "盒子"
},
methods: {
show1: function(eve) {
console.log("show1", this, eve);
this.msg = "this is a box1 data";
},
show2(eve) {
console.log("show2", this, eve);
this.msg = "this is a box2 data";
},
show3: (eve) => {
console.log("show3", this, eve);
this.msg = "this is a box3 data";
}
}
})
输出结果
发现使用箭头函数的show3的指向不是Vue对象