vuejs 箭头函数下this指向问题

今天跳转的时候遇到一个问题

在子组件中

this.$router.push({
path:'/easylearn'
})

报错,no $router

后面差错,是因为写了箭头函数的缘故,this指向了当前域

这里应该直接用函数写

goFirst正常,goSecond报错

methods:{
    goFirst(){
      console.log(this)
      this.$router.push({
        path:'/easylearn'
      })
    },
    goSecond:(()=>{
       this.$router.push({}) 
    })
 },
原文地址:https://www.cnblogs.com/hodgson/p/9167069.html