【发布时间】:2017-03-13 12:55:54
【问题描述】:
我开始使用 Vue.js,而不是 AngularJS,我在vue-router 和angular-ui-router 上遇到了一个问题。
每个 angular-ui-router 用户都知道这样的事情:
$stateProvider
.state('myState', {
url: '/my/url',
templateUrl: 'my/template/path/template.html',
controller: 'myTemplateController',
controllerAs: 'myAsController'
});
是(也许?)使用 uiRouter 的好方法之一。
当我第一次接触 uiRouter 时,我觉得用起来很舒服。
现在我正在使用 vue-router,我想知道它是否可以处理类似 templateUrl 属性的东西(我不关心其他属性,当然,对于 Vue.js 可能没有更多意义)无需每次都在 .js 文件中编写 HTML 代码(这很丑陋),而是将其抽象到局部视图中。
我问这个是因为在official documentation 中,每个示例都声明为:
const routes = [
{
path: '/my/url',
component: {
template: '<tag>html here or text or sth else...</tag>'
}
}
];
const router = new VueRouter({routes});
const app = new Vue({router}).$mount('#myApp');
它很清楚,解释得很好,而且效果很好。但这不是我想要的。
首先在 Stackoverflow 上搜索我得到了 this thread 里面(也许?)我在问什么,但我仍然不明白在做什么。
【问题讨论】:
标签: javascript angular-ui-router vue.js vue-router