?
1. router-link
1. 不帶參數(shù)
<router-link :to="{name:'home'}"> <router-link :to="{path:'/home'}"> //name,path都行, 建議用name // 注意:router-link中鏈接如果是'/'開始就是從根路由開始,如果開始不帶'/',則從當前路由開始。
2.帶參數(shù)
<router-link :to="{name:'home', params: {id:1}}"> // params傳參數(shù) (類似post) // 路由配置 path: "/home/:id" 或者 path: "/home:id" // 不配置path ,第一次可請求,刷新頁面id會消失 // 配置path,刷新頁面id會保留 // html 取參 $route.params.id // script 取參 this.$route.params.id <router-link :to="{name:'home', query: {id:1}}"> // query傳參數(shù) (類似get,url后面會顯示參數(shù)) // 路由可不配置 // html 取參 $route.query.id // script 取參 this.$route.query.id
2. this.$router.push() (函數(shù)里面調用)
1. 不帶參數(shù)
this.$router.push('/home') this.$router.push({name:'home'}) this.$router.push({path:'/home'})
2. query傳參
this.$router.push({name:'home',query: {id:'1'}}) this.$router.push({path:'/home',query: {id:'1'}}) // html 取參 $route.query.id // script 取參 this.$route.query.id
3. params傳參
this.$router.push({name:'home',params: {id:'1'}}) // 只能用 name // 路由配置 path: "/home/:id" 或者 path: "/home:id" , // 不配置path ,第一次可請求,刷新頁面id會消失 // 配置path,刷新頁面id會保留 // html 取參 $route.params.id // script 取參 this.$route.params.id
4. query和params區(qū)別
query類似 get, 跳轉之后頁面 url后面會拼接參數(shù),類似?id=1, 非重要性的可以這樣傳, 密碼之類還是用params刷新頁面id還在
params類似 post, 跳轉之后頁面 url后面不會拼接參數(shù) , 但是刷新頁面id 會消失。
3. this.$router.replace()
(用法同上,push)
4. this.$router.go(n) ()
this.$router.go(n)
向前或者向后跳轉n個頁面,n可為正整數(shù)或負整數(shù)。文章來源:http://www.zghlxwxcb.cn/news/detail-436675.html
為了保存收藏,轉載到自己的文章中, 原創(chuàng)文章大佬 :?http://t.csdn.cn/QSVJF文章來源地址http://www.zghlxwxcb.cn/news/detail-436675.html
到了這里,關于詳解vue 路由跳轉四種方式 (帶參數(shù))[轉載]的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!