Files
2024-09-27 02:06:13 +08:00

54 lines
1.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<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://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.0.6/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
<h1>{{ test }}</h1>
<p>
<router-link to="/zhansan/23">Go to 关于公司</router-link>
<router-link to="/contact?name=liubing ">Go to 联系我们</router-link>
</p>
<router-view></router-view>
</div>
<script>
// 局部注册两个组件
const Foo = {
created(){
console.log(this.$route.params.id)
},
template: '<h2>关于公司 {{ $route.params.id }}</h2>'
}
const Bar = { template: '<h2>联系我们 {{ $route.query.name }}</h2>' }
const routes = [
{ path: '/zhansan/:id', component: Foo },
{ path: '/contact', component: Bar }
];
const router = new VueRouter({
routes // (缩写) 相当于 routes: routes
})
new Vue({
el: "#app",
router,
data: {
test: '我是根组件'
}
})
</script>
</body>
</html>