axios回调函数中的this为何是undifine?

this.$axios.get("./data.json").then(function(result){      console.log(this) //undefine
    })

关于axios回调函数this指向的问题,网上的大部分文章只是推荐用箭头函数取代普通函数解决,但是却没有解释为什么this会指向undefine,在我的理解里应该是指向window,因为这个匿名回调函数的调用者必然是window对象,但是结果却是undefined,感觉我好不容易建立起的对this指向的认识又崩溃了。。。-。-


千巷猫影
浏览 1127回答 1
1回答

RISEBY

this.$axios.get("./data.json").then(result => {      console.log(this) //undefine     })这样写,在axios的回调里,this不指向vue了,用箭头函数 () => {}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5
Vue.js