傳字符串
#傳送
this.$router.push({
name: `TestVueRouterTo`,
params: {
page: '1', code: '8989'
}
})
#接收
getRouterData() {
this.page = this.$route.params.page
this.code = this.$route.params.code
console.log('page', this.page)
console.log('code', this.code)
}
參考網頁:https://www.cnblogs.com/beka/p/8583924.html
傳對象
在路由傳參中,只能傳取字符串,如果需要傳對象的話,需將字符串靠JSON轉為字符串。接收后靠JSON解析
傳:
// 列表頁點擊跳轉
let data = JSON.stringify(result) // result傳遞的query參數。我們轉為string
this.$router.push({path: '/wx/detail', query: {res: data}})
收:
// 詳情頁獲取
let data = JSON.parse(this.$route.query.res)
this.result = Object.assign({}, data)