Vue router

2020-10-16 14:00:06

初次接觸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為什麼沒有生效嗎???