箭头函式和普通函式之间的区别
箭头函式并没有自己的 thisthis 会往上找到最近的函数主体作为物件this 指向定义时所在的物件,而不是呼叫时所在的物件实际 mounted 资料
mounted() { axios.get('https://') .then(function(res){ this.spots = res.data; console.log(this); // undefined })}
mounted() { axios.get('https://') .then((res) => { this.spots = res.data; console.log(this); // Vue })}
参考来源:
https://iter01.com/141625.html
https://blog.scottchayaa.com/post/2019/03/09/jquery-closure-function-this/