命令路由
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<div id="app">
<router-link :to="{name:'user' , params: { id: 123}}">User组件</router-link>
<router-view></router-view>
</div>
<script>
const User = {
template: "<div><h1>这是User的组件 {{ $route.params.id }}</h1></div>"
}
const router = new VueRouter({
routes: [{
path: "/user/:id",
name: 'user',
component: User
}]
})
var vm = new Vue({
el: '#app',
data: {
},
router: router
})
</script>
</body>
</html>