首先我在home.vue中定义

updates(id){
this.$router.push({
path:'/world',
name:'world',
params:{
id : id
}
})
}
其次在另一个页面world.vue中

export default {
name: '',
data () {
return {
id: ''
}
},
created(){
this.getParams()
},
methods: {
getParams () {
// 取到路由带过来的参数
var routerParams = this.$route.params.id
// 将数据放在当前组件的数据内
this.id = routerParams
}
},
watch: {
// 监测路由变化,只要变化了就调用获取路由参数方法将数据存储本组件即可
'$route': 'getParams'
}
}

 

posted on 2020-03-13 09:06  学止  阅读(8718)  评论(0编辑  收藏  举报