【发布时间】:2017-04-01 07:06:43
【问题描述】:
如何在通过 ajax 获取路由数组后动态创建?
有没有办法在路由器初始化后向路由器添加/推送新路由?
这不起作用:
new Vue({
el: '#app',
template: '<App/>',
data: {
content: []
},
created: function () {
this.$http.get('dummyjsondatafornow').then((response) => {
// this doesn't work when creating the VueRouter() outside the Vue instance, as in the docs.
// this.$router.options.routes.push({ path: '/about', component: About })
let routes = [
{ path: '/about', component: About }
]
// this doesn't work either
this.router = new VueRouter({
routes: routes
})
})
},
// router: router,
components: { App }
})
【问题讨论】:
-
我可以理解为服务器端创建动态路由,但为 SPA 创建动态路由?重点在哪里?
-
好吧,SPA 的内容(包括页面/路由)是在与 SPA 不同的系统 (CMS) 中管理的。我还能如何解决这个问题?
标签: vue.js vue-resource vue-router