index js file
I tried using Vue Router programatically, but it was not working for me. After searching online, I found that everyone used this.$router.push()
.
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import BecomeHost from '@/components/BecomeHost'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/become_host',
name: 'BecomeHost',
component: BecomeHost
}
]})
component.vue
When the response was successful, I tried calling the following code but it did not work:
if (res.data.status === 'success') {
localStorage.setItem('user', JSON.stringify(res.data.data))
let user = JSON.parse(localStorage.getItem('user'))
this.setUserData(user)
this.$router.push('/become_host')
}