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
}
});
轉載:https://www.cnblogs.com/matd/p/11573819.html