vue頁面params傳值的坑
阿新 • • 發佈:2018-11-15
a.vue向b.vue傳值
a.vue
this.$router.push({
path: '/payType',
query: {
putUpList: this.putUpList,
name:'111'
},
params:{
cartList: this.cartList,
totalMoney: this.totalMoney
}
});
b.vue
mounted:function(){
console.log(this.$route.params)
console.log(this .$route.query)
}
坑來了
query可以拿到,params拿不到
需要在註冊路由的地方給路由加上name引數
const router = new VueRouter({
routes:[{
...
},{
path:'/payType',
name:'inputComp',
component: payType
}]
})
a.vue跳轉路由的地方同樣加上name引數,b.vue就可以拿到params了
this.$router.push({
path: '/payType' ,
name: 'inputComp',
query: {
putUpList: this.putUpList,
name:'111'
},
params:{//一定要設定name,才可以傳params
cartList: this.cartList,
totalMoney:this.totalMoney
}
});