相关疑难解决方法(0)

如何在Vue-router中使用addroutes方法?

我创建了一个函数“ 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)

javascript ecmascript-6 vue.js vue-router

5
推荐指数
1
解决办法
5344
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

vue-router ×1

vue.js ×1