用导航钩子函数
https://router.vuejs.org/zh-c...
<div id="app">
<router-link to="/a">aaaa</router-link>
<router-link to="/b">index</router-link>
<transition :name="v">
<router-view ></router-view>
</transition>
</div>
const router = new VueRouter({
routes: [
{
path: '/a',
component: {
template: '<span>a</span>'
}
},
{
path: '/b',
component: {template: '<span>b</span>'}
}
]
})
var app = new Vue({
el: '#app',
data: {
v: 1
},
router,
watch: {
'$route'(to,from){
this.v = 2;
}
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…