初次接触Vue,在使用Router时,出现了如下的报错信息
[Vue warn]: Unknown custom element: <router-link> - did you register the component correctly?
For recursive components, make sure to provide the "name" option.
(found in <Root>)
查看项目是否加载vue.js文件和vue-router.js文件,项目加载两个vue脚本文件。
详细代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>router测试</title>
<script src="js/vue-router.js"></script>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<h1>hello word</h1>
<p>
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
</p>
<router-view></router-view>
</div>
</body>
<script>
const Foo = {
template: '<div>foo</div>'
}
const Bar = {
template: '<div>bar</div>'
}
const routes = [{
path: '/foo',
component: Foo
},
{
path: '/bar',
component: Bar
}
]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount("#app")
</script>
</html>
有大佬,帮忙看一下,这个router为什么没有生效吗???