国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

詳解vue 路由跳轉四種方式 (帶參數)

2019-11-19 11:41:19
字體:
來源:轉載
供稿:網友

1.  router-link

1. 不帶參數 <router-link :to="{name:'home'}"> <router-link :to="{path:'/home'}"> //name,path都行, 建議用name // 注意:router-link中鏈接如果是'/'開始就是從根路由開始,如果開始不帶'/',則從當前路由開始。 2.帶參數 <router-link :to="{name:'home', params: {id:1}}"> // params傳參數 (類似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傳參數 (類似get,url后面會顯示參數)// 路由可不配置// html 取參 $route.query.id// script 取參 this.$route.query.id

2.  this.$router.push() (函數里面調用)

1. 不帶參數 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.id3. 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.id4. query和params區別query類似 get, 跳轉之后頁面 url后面會拼接參數,類似?id=1, 非重要性的可以這樣傳, 密碼之類還是用params刷新頁面id還在 params類似 post, 跳轉之后頁面 url后面不會拼接參數 , 但是刷新頁面id 會消失

3.  this.$router.replace() (用法同上,push)

4.  this.$router.go(n) ()

this.$router.go(n)

向前或者向后跳轉n個頁面,n可為正整數或負整數

ps : 區別

this.$router.push

跳轉到指定url路徑,并想history棧中添加一個記錄,點擊后退會返回到上一個頁面

this.$router.replace

跳轉到指定url路徑,但是history棧中不會有記錄,點擊返回會跳轉到上上個頁面 (就是直接替換了當前頁面)

this.$router.go(n)

向前或者向后跳轉n個頁面,n可為正整數或負整數

總結

以上所述是小編給大家介紹的詳解vue 路由跳轉四種方式 (帶參數),希望對大家有所幫助,如果大家有人疑問歡迎給我留言,小編會及時回復大家的!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 名山县| 宣威市| 九龙城区| 威宁| 翼城县| 巫山县| 连云港市| 射洪县| 铁岭县| 临邑县| 通化县| 弥勒县| 泾川县| 运城市| 开原市| 元谋县| 大连市| 宽城| 敦煌市| 望奎县| 霍城县| 岗巴县| 上蔡县| 庆安县| 水城县| 封丘县| 昌都县| 资源县| 碌曲县| 息烽县| 樟树市| 张家界市| 右玉县| 沧州市| 高碑店市| 汨罗市| 隆德县| 寻甸| 甘谷县| 定襄县| 乌拉特中旗|