<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
<h1>Hello !</h1>
<p>
<router-link to="/hash1">切换至com1</router-link>
<router-link to="/hash2">切换至com2</router-link>
</p>
<router-view></router-view>
</div>
</body>
<script>
/
const com1 = { template: '<div>路由1</div>' }
const com2 = { template: '<div>路由2</div>' }
const routes = [
{ path: '/hash1', component: com1 },
{ path: '/hash2', component: com2 }
]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount('#app');
</script>
</html>
为什么运行不出来,报错说vue-router没被定义。
- 复制链接
- 举报