vue菜单之跳转传参
a.vue 跳转 b.vue
第一种:类似get方式,浏览器地址栏显示参数
在a.vue中这样写:
data() {
retuen {
id: '3'
}
},
methods: {
getById(){
this.$router.push({
path: '/example/tree', // 跳转菜单的路径
query: {
id: this.id // 传入的参数
}
})
}
}
在b.vue中这样写:
data() {
retuen {
id: ''
}
},
// 在生命周期函数中接受参数
created() {
this.id = this.$route.query.id
console.log( this.id )
}
第二种:类似post方式,浏览器地址栏不显示参数
在a.vue中这样写:
data() {
retuen {
id: '3'
}
},
methods: {
getById(){
this.$router.push({
name: 'Tree', // 跳转菜单的路径
params: {
id: this.id // 传入的参数
}
})
}
}
在b.vue中这样写:
data() {
retuen {
id: ''
}
},
// 在生命周期函数中接受参数
created() {
this.id = this.$route.params.id
console.log( this.id )
}