<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>路由的参数</title>
</head>
<body>
<div id="app">
<router-link to="/article/1/a">商品1</router-link>
<router-link to="/article/2/b">商品2</router-link>
<router-link to="/article/3/c">商品3</router-link>
<router-view></router-view>
</div>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="node_modules/vue-router/dist/vue-router.js"></script>
<script>
// $router : 上面放的都是一些方法
// $route : 放了一些键值对
let article ={
created(){
console.log(this.$route);
console.log(this.$router);
// $route.params :存储了当前路由的参数;
},
template:"<div>第{{$route.params.id}}篇文章</div>"
};
let routes = [
{path:"/article/:id/:txt",component:article}
];
let router = new VueRouter({
routes
})
let vm = new Vue({
el: '#app',
data: {},
router
});
</script>
</body>
</html>
网友评论