我正在使用Vue 2.x和Vuex 2.x创建一个Web应用程序.我通过http调用从远程位置获取一些信息,我希望如果该调用失败,我应该重定向到其他页面.
GET_PETS: (state) => {
return $http.get('pets/').then((response)=>{
state.commit('SET_PETS', response.data)
})
},
error => {this.$router.push({path:"/"}) }
)
}
Run Code Online (Sandbox Code Playgroud)
但是this.$router.push({path:"/"})给了我以下错误.
未捕获(承诺)TypeError:无法读取未定义的属性'push'
如何实现这一目标.
模拟JsFiddle:在这里