057——VUE中vue-router之路由参数默认值的设置

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue-router之路由参数默认值的设置</title>
<script src="vue.js"></script>
<script src="vue-router.js"></script>
</head>
<body>
<div id="demo">
<router-link to="/content">链接</router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="content">
<div>
id:{{id}}
</div>
</script>
<script>
const content = {
template: "#content",
data() {
return {
id:0
}
},
mounted() {
this.id = this.$route.params.id;
if (!this.id) {
this.id = 1;
}
}
}
let routes=[
{path:'/content/:id?',component:content}
]
let router=new VueRouter({routes});
new Vue({
el:"#demo",
router
});
</script>
</body>
</html>

  

上一篇:虚拟机下CentOS找不到网卡eth0的解决方法


下一篇:Android RecyclerView 水平滚动+自动循环轮播