我创建了一个函数“ addroute()”来动态添加路由,但是它不起作用(路由器未更改)。这是使用addRoutes方法的正确方法吗?我从教程中学到了这一点。如果没有,那么给我一个正确的例子,谢谢!
...
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
...
Run Code Online (Sandbox Code Playgroud)