A组件点击跳到B组件 , 携带参数过去
A组件中 (传参)
这里的Bpage是router --> index.js中B页面配置的name
<div v-for="(item, index) in list" :key="index" @click="toDetail(item.username)">
{{ item.title }}
</div>
toDetail(info) {
this.$router.push({
name: "Bpage",
//params是个对象 , 可以写很多个参数传过去
params: {
uName:info
}
})
}
B组件(接收参数)
mounted() {
this.userName= this.$route.params.uName
},
data() {
return {
userName: ""
}
},