箭头函数this指向

在回调函数中:具有代表性的为axios的回调

普通函数
let _this=this
axios.get('/user', {
    params: {
    }
  })
  .then(function (response) {
    console.log(_this.$route.name) //使用_this指向vue实例,可以获取到name
  })
  .catch(function (error) {
    console.log(_this.$route.name) //使用_this指向vue实例,可以获取到name
  });
箭头函数
axios.get('/user', {
    params: {
    }
  })
  .then(response => {    //箭头函数中this指向vue实例
    console.log(this.$route.name)
  })
  .catch(error => {      //箭头函数中this指向vue实例
    console.log(this.$route.name)
  });

文章参考:https://www.jianshu.com/p/f722e3667cf6

原文地址:https://www.cnblogs.com/xxr0218/p/14066697.html