vue 路由跳轉方式


1、第一種是最為常用的,使用push跳轉:

//字符串形式直接跳轉
this.$router.push('/goods/add')
//對象的形式進行跳轉
this.$router.push({path:'/goods/add'})
 
//對象的形式並且帶參數
this.$router.push({path:'/goods/add?url=123'})
this.$router.push({path: '/goods/add', query: {selected: "2"}})
 
 
 接受參數:
 //獲取通過query帶過來的參數對象
 // console.log(this.$route.query)

2、第二種也是比較常見的,使用標簽跳轉:

<router-link to="/goods/add">點擊跳轉</router-link>

3、第三種是使用replace跳轉:

//導航后不會留下 history 記錄。即使點擊返回按鈕也不會回到這個頁面。
this.$router.replace({path:'/goods/add'});
 
//帶參數方式與push相同(獲取參數也一樣)
this.$router.replace({path:'/goods/add', query: {selected: "3"}});
 
//push方法也可以傳replace
//push在加上replace: true后,它不會向 history 添加新記錄,而是跟它的方法名一樣 —— 替換掉當前的 history 記錄。
 this.$router.push({path: '/home', replace: true})

4、第四種是使用go方式跳轉:

//跳轉到上一頁
this.$router.go(-1)
//跳轉到上上頁
 this.$router.go(-2)

 


免責聲明!

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



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