vue路由傳參params 和 query 區別

 使用區別:

params要用name來引入,使用 this.$route.params 來獲取。
query要用path來引入(name也可以), 使用 this.$route.query來獲取。

外觀展示區別:

query同ajax中get的URL傳參,瀏覽器地址欄中顯示參數。
params則類似於post。URL上看不到參數,缺點刷新後獲取的值爲undefiend

推薦使用query,遇到問題也好排查

 

 

 如何使用:

this.$router.push(`/describe/${id}`)
//
this.$router.push({
        path: `/describe/${id}`
      })
//

this.$router.push({
        name: 'Describe',
        params: {id}
      })
//
this.$router.push({
        path: '/describe',
        query: {id}
      })

 

 

 

 

.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章