javasript语法中的this指的是整个页面实例
1、普通函数的this不再指向页面的this,而是发生了改变,指向自己函数内部的this,此时如果我们需要取页面this的值就需要备份给一个新的变量操作
data:{
a:1;
}
let that = this; //this指向的对象发生了变化,故需要在函数前将this指向的对象提前保存一下
sum:funtion(){
console.log(that.a); //1
console.log(this.a); // undefined
}
2、箭头函数的this和外部的页面实例指的this是同一个this,所以是可以直接取到页面上的变量
data:{
a:1,
},
sum(()=>{
console.log(this.a); //1
})