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({}) 
    })
 },
posted @ 2018-06-11 14:58  素绚  阅读(954)  评论(0编辑  收藏  举报