路由常用配置
this.$router.go(-1)
this.$router.push('/')
<buttton type="button" @click="$router.go(-1)">后退2</buttton>
{ path: '/user/:id', component: User }
<router-link to="/user/foo">/user/foo</router-link>
<router-link to="/user/bar">/user/bar</router-link>
console.log(this.$route.params.id)
提醒一下,当使用路由参数时,例如从 /user/foo
导航到 /user/bar
,原来的组件实例会被复用。因为两个路由都渲染同个组件,比起销毁再创建,复用则显得更加高效。不过,这也意味着组件的生命周期钩子不会再被调用。
下面的watch$route只有在 /user/foo 和user/bar 之间切换的时候才会被调用, 从/home切换到/user/foo 是不会被调用的
const User = {
template: '...',
watch: {
'$route' (to, from) {
// 对路由变化作出响应...
}
}
}
this.$router和this.$route的区别
1. this.$router:
表示全局路由器对象,项目中通过router路由参数注入路由之后,在任何一个页面都可以通过此方法获取到路由器对象,并调用其push(), go()等方法;
2. this.$route:
表示当前正在用于跳转的路由器对象,可以调用其name、path、query、params等方法;
注:使用的时候注意拼写,两个很像,就差一个字母,经常会因为写错而导致调用的方法无效,而且浏览器的控制台中还不会报错。。。
vue-cookies
vue axios配置及session问题
https://blog.csdn.net/qq_26566331/article/details/72478923