vue之this.$router.query和this.$router.params的使用與區別


一  this.$router.query的使用:

router/index.js

 1     {
 2      path:'/mtindex',
 3      component: mtindex,
 4      //添加路由
 5      children:[
 6        {
 7         path:':shopid',
 8         component:guessdetail
 9        }
10      ]     
11     },

2 傳參數

1 this.$router.push({
2         path: '/mtindex/detail', query:{shopid: item.id}
3        });

3 獲取參數

1 this.$route.query.shopid

4 url的表現形式(url中帶有參數)

http://localhost:8080/#/mtindex/detail?shopid=1

this.$router.params的使用:

1 router/index.js

 1 {
 2      path:'/mtindex',
 3      component: mtindex,
 4      //添加路由
 5      children:[
 6        {
 7         path:"/detail",
 8         name:'detail',
 9         component:guessdetail
10        }
11      ]     
12 
13     },

2 傳參數(params相對應的是name  query相對應的是path)

1 this.$router.push({
2         name: 'detail', params:{shopid: item.id}、
3         });

3 獲取參數

1 this.$route.params.shopid

4 url的表現形式(url中沒有帶參數)

http://localhost:8080/#/mtindex

 


免責聲明!

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



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