我按照vue-router文档上的例子写代码:
html:
<div id="app">
<p>
<router-link to="/user/foo">/user/foo</router-link>
<router-link to="/user/foo/profile">/user/foo/profile</router-link>
<router-link to="/user/foo/posts">/user/foo/posts</router-link>
</p>
<router-view></router-view>
</div>
<script src="../node_modules/vue/dist/vue.min.js"></script>
<script src="../node_modules/vue-router/dist/vue-router.min.js"></script>
<script src="app.js"></script>
app.js:
const User = {template: '<div><p>User {{$route.params.id}}</p><router-view></router-view></div>'}
const UserProfile = { template: '<div>Profile</div>' }
const UserPosts = { template: '<div>Posts</div>' }
const router = new VueRouter({
routes: [
{
path: '/user/:id', component: User,
children: [
{ path: 'profile', component: UserProfile },
{ path: 'posts', component: UserPosts }
]
}
]
})
const app = new Vue({
router
}).$mount('#app')
但是router-link并没有生成a标签,不知道哪里出错了
试了一下,完全没问题啊。是不是 Vue 或者 VueRouter 的文件有问题,看看控制台有没有错误信息提示。
https://jsfiddle.net/KingMari...