【发布时间】:2019-04-16 01:57:32
【问题描述】:
我目前正在使用 Vue 和 Vue Router CDN。我想使用 Vue 路由器将单个文件组件 (user.html) 导入我的 index.html。但是当我点击“转到用户”时,数据没有显示。我阅读了一些关于 Vue 路由器的指南,但他们使用 NPM 或 CIL 而不是 Vue CDN。 索引.html
<div id="app">
<h1>Hello App!</h1>
<p>
<!-- use router-link component for navigation. -->
<!-- specify the link by passing the `to` prop. -->
<!-- `<router-link>` will be rendered as an `<a>` tag by default -->
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
<router-link to='/User.html'>Go to User</router-link>
</p>
<!-- route outlet -->
<!-- component matched by the route will render here -->
<router-view></router-view>
</div>
<script>
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const User = { template: '#test'}
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{
path:'/User.html', component: User
}
]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount('#app')
</script>
用户.html
<template id = "test">
fsjdfjdfldskjflkd
</template>
【问题讨论】:
标签: vue.js vuejs2 vue-component vue-router