Vue3.x出來有一陣子了,今天用它的時候發現Vue2中的this.$router.push竟然不能用了!!!!!,真是服了,還得花點時間瞅瞅咋回事,所以.....還是總結下吧
目錄
1.Vue3.x路由跳轉
2.獲取引數
3. router-link
4.總結
1.Vue3.x路由跳轉
不要this了,直接參考路由物件,看下圖:
import router from '@/router/index.js'

用這個路由物件router去push(剩下的和Vue2.x一樣)
router.push({name:'user',params:{id:props.videoInfo.author.ID}});

我們列印出這個router看看里頭是啥?看到currentRoute熟悉么親?所以原來this.$route也不用了(雖然他原來也是$router內部的currentRoute)

2.獲取引數
原來獲取引數用this.$route.params獲取,現在是這樣的,
router.currentRoute.value.params.id
來具體看看 currentRoute里面是啥吧

3. router-link
很開心<routerlink/>沒有變化,還是以前那么用
<router-link :to="{name:'user',params:{id:videoInfo.author.ID}}">點擊跳轉</router-link>
4.總結
整體上來講vue3使用上是方便了,但是很多小的東西和原來不一樣了,還真的找找,歡迎大佬們補充,,,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/254039.html
標籤:其他
