this 指当前元素,一般函数中,例如vue中axios的请求接口数据
错误指向
created(){
axios.get("https://zsl.zmzhi.com/api/goods/getCategoryTree").then(funtion(data){
this.carAssembly = data.data.data;
console.log(this.carAssembly)
})
此时this 指向会undefined
created(){
axios.get("https://zsl.zmzhi.com/api/goods/getCategoryTree").then((data)=>{
this.carAssembly = data.data.data;
console.log(this.carAssembly)
})
改写成箭头函数时this生效