路由傳值的方式有哪幾種


Vue-router傳參可以分為兩大類,分別是編程式的導航 router.push和聲明式的導航
1、router.push
1.1)字符串:直接傳遞路由地址,但是不能傳遞參數
this.$router.push("home")
對象:
1.2)命名路由 這種方式傳遞參數,目標頁面刷新會報錯
this.$router.push({name:"news",params:{userId:123})
1.3)查詢參數 和name配對的式params,和path配對的是query
this.$router.push({path:"/news',query:{uersId:123})
1.4)接收參數 this.$route.params this.$route.query
2、聲明式導航
2.1)字符串 <router-link to="news"></router-link>
2.2)命名路由 <router-link :to="{name:'news',params:{userid:1111}}"></router-link>
2.3)查詢參數 <router-link :to="{path:'/news',query:{userId:1111}}"></router-link>


免責聲明!

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



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