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)
