this.$router.push 傳參


index頁面
1.params
this.$router.push()方法中path不能與params同用,否則param會失效,所以用name來指定頁面,params來傳遞數據內容。

 1 <template>
 2 <img src="../../static/images/indexTermianal/teacher.png" alt="" @click ="go()" > 
 3 </template>
 4 <script>
 5 methods:{
 6   go:function(){
 7     this.$router.push({
 8       name:'indext',
 9       params:{
10         userId:1
11       }
12     })
13   }
14 }
15 </script>

 

在目標頁面通過this.$route.params獲取參數:
<p>{{this.$route.params.userId}}</p>

2.query
頁面通過path和query傳遞參數,該實例中row為某行表格數據

 1 methods:{
 2     go:function(){
 3         this.$router.push({
 4         path:'/indext',
 5       query:{
 6         userId:1
 7       }
 8      })
 9   }
10 },        

 



目標頁面this.$route.query.userId獲取數據

<p>{{this.$route.query.userId}}</p>


免責聲明!

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



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