router-link params傳參


1、router.js配置

需要在路徑后定義上要傳的屬性名 --》       /:屬性名(query方式不需要)

{
  path: '/CreateProgress/:name1',
  name: 'CreateProgress',
  component:CreateProgress
}
2、傳參
與query不同的是  params是根據路由的name跳轉的   而query是根據 path跳轉的
<router-link :to="{name:'CreateProgress',params:{name1:'haha',name2:'enen'}}" target="_blank">xxxxx</router-link>
 
3、接受參數的方式和query相同
this.$route.params
this.$route.params.name1
 
query是
this.$route.query
this.$route.query.name1
 
 
當然 用params方式傳參時,同時也可以用query方式傳參
< router-link :to = "{ name:'CreateProgress',params: { name1: '參數'},query: { queryId: status2 }}" >xxxxx </ router-link >
接受方式 按照自己的接受方法接受 就行
 
 
 
也可以使用編程式跳轉    是$router而不是$route    要跟接受參數的區分清楚
this .$router.push({ name: 'CreateProgress' ,params: { name1:'參數'},query: { queryId: status2 }});
可以用click事件來觸發


免責聲明!

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



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