雾观远山

博客园 首页 新随笔 联系 订阅 管理

porps传参(最常用的 布尔传值)(基于前面的步骤进行修改)


①index.js //定义动态路由 props:true
const routes =[
{path:"/user/:id/:name/:age",component:User,props:true}
]


②app.vue //定义传参格式
<div>
<h6>路由导航</h6>
<div>
<router-link to="/foo">&nbsp &nbsp foo</router-link>
<router-link to="/bar">&nbsp &nbsp bar</router-link>
<router-link to="/user">&nbsp &nbsp user</router-link>
<router-link to="/user/1/lsq/18">&nbsp &nbsp user1</router-link>
<router-link to="/user/2/zsj/19">&nbsp &nbsp user2</router-link>
<router-link to="/user/3/zzr/18">&nbsp &nbsp user3</router-link>
</div>
<h6>路由出口</h6>

<router-view></router-view>

 


:to="{path:'/listview',params:{id:item.id}
③user.vue // 定义接收参数

<template>
<p>{{id}}</p>
<p>{{name}}</p>
<p>{{age}}</p>
</template>

<script>
export default {
name: "User",
props:['id','name','age']
}
</script>

<style scoped>

</style>

posted on 2022-05-12 00:13  雾观远山  阅读(53)  评论(0编辑  收藏  举报