I have created a function "addroute()" to add routes dynamically,but it didn't work(the router does not changed).
Is this a right way to use addRoutes method? I have learned this from tutorial.
If not then give me a correct example,Thanks!
...
const Bar={
template:'#panels',
data(){
return {title:'badss'}
}
};
const Foo={
template:"#panels",
data(){
return {title:'hell'}
}
};
const router = new VueRouter({
routes:[
{path:'/foo',component:Foo},
{path:'/bar',component:Bar}
]
});
new Vue({
el:'#root',
router:router,
data:{
stats:stats
},
methods: {
//
},
});
function addroute(){//watch here
router.addRoutes([{path:'/ioio',component:{template:'#panels'}}])
}
setInterval("addroute()", 2000)//watch here
...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…