vue頁面params傳值的必須傳name


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
    }
});

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM