av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

vue跳轉(zhuǎn)頁(yè)面常用的幾種方法匯總

瀏覽:135日期:2022-06-01 14:57:33
目錄
  • 1:router-link跳轉(zhuǎn)
    • 1.不帶參數(shù)
    • 2.帶params參數(shù)
    • 3.帶query參數(shù)
  • 2:this.$router.push()
    • 1.不帶參數(shù)
    • 2.query傳參 
    • 3.params傳參
    • 4.query和params區(qū)別
  • 3:this.$router.replace() 
    • 4:this.$router.go(n) 
      • ps : 區(qū)別
        • 總結(jié)

          vue跳轉(zhuǎn)頁(yè)面有好幾種不同方法,下面將通過(guò)實(shí)例代碼給大家介紹,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下。

          1:router-link跳轉(zhuǎn)

          1.不帶參數(shù)

          <router-link :to="{name:"home"}">?
          <router-link :to="{path:"/home"}"> //name,path都行, 建議用name?
          // 注意:router-link中鏈接如果是"/"開(kāi)始就是從根路由開(kāi)始;如果不帶"/",則從當(dāng)前路由開(kāi)始。?

          2.帶params參數(shù)

          <router-link :to="{name:"home", params: {id:123456}}">?
          // params傳參數(shù) (類似post)
          // 路由配置 path: "/home/:id" 或者 path: "/home:id"?
          // 不配置path ,第一次可請(qǐng)求,刷新頁(yè)面id會(huì)消失;配置path,刷新頁(yè)面id會(huì)保留。
          // html 取參 $route.params.id ? ?script 取參 this.$route.params.id?

          3.帶query參數(shù)

          <router-link :to="{name:"home", query: {id:123456}}">?
          // query傳參數(shù) (類似get,url后面會(huì)顯示參數(shù))
          // 路由可不配置
          // html 取參 $route.query.id ? ?script 取參 this.$route.query.id

          2:this.$router.push()

          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:"123456"}})
          this.$router.push({path:"/home",query: {id:"123456"}})
          // html 取參 $route.query.id ? ?script 取參 this.$route.query.id?

          3.params傳參

          this.$router.push({name:"home",params: {id:"123456"}}) // 只能用 name
          // 路由配置 path: "/home/:id" 或者 path: "/home:id" ,
          // 不配置path ,第一次可請(qǐng)求,刷新頁(yè)面id會(huì)消失
          // 配置path,刷新頁(yè)面id會(huì)保留
          // html 取參 $route.params.id ? ?script 取參 this.$route.params.id

          4.query和params區(qū)別

          query類似get, 跳轉(zhuǎn)之后頁(yè)面url后面會(huì)拼接參數(shù),類似?id=123456, 非重要性的可以這樣傳, 密碼之類還是用params刷新頁(yè)面id還在

          params類似post, 跳轉(zhuǎn)之后頁(yè)面url后面不會(huì)拼接參數(shù), 但是刷新頁(yè)面id會(huì)消失。 

          3:this.$router.replace() 

          用法同上,和第2個(gè)的this.$router.push方法一樣。

          4:this.$router.go(n) 

          <button @click="upPage">[上一頁(yè)]</button>
          <button @click="downPage">[下一頁(yè)]</button>
          upPage() {
          this.$router.go(-1); ?// 后退一步記錄,等同于 history.back()
          },
          downPage() {
          this.$router.go(1); ? // 在瀏覽器記錄中前進(jìn)一步,等同于 history.forward()
          }

          向前或者向后跳轉(zhuǎn)n個(gè)頁(yè)面,n可為正整數(shù)或負(fù)整數(shù)

          ps : 區(qū)別

          this.$router.push

          跳轉(zhuǎn)到指定url路徑,并向history棧中添加一個(gè)記錄,點(diǎn)擊后退會(huì)返回到上一個(gè)頁(yè)面。

          this.$router.replace

          跳轉(zhuǎn)到指定url路徑,但是history棧中不會(huì)有記錄,點(diǎn)擊返回會(huì)跳轉(zhuǎn)到上個(gè)頁(yè)面 (直接替換當(dāng)前頁(yè)面)。

          this.$router.go(n)

          向前或者向后跳轉(zhuǎn)n個(gè)頁(yè)面,n可為正整數(shù)或負(fù)整數(shù)。

          總結(jié)

          以上所述就是給大家介紹的vue路由跳轉(zhuǎn)四種方式,僅為個(gè)人經(jīng)驗(yàn)。希望能給大家一個(gè)參考,也希望大家多多支持。

          標(biāo)簽: JavaScript
          相關(guān)文章:
          主站蜘蛛池模板: 欧美精品一 | 欧美一区视频在线 | 国产91网站在线观看 | 久久久久国产精品 | 在线观看日本网站 | 亚洲综合日韩精品欧美综合区 | 中文字幕视频一区二区 | 欧美精品一区二区三区蜜桃视频 | 国产精品国产三级国产aⅴ中文 | 激情a| 色综合久久天天综合网 | 欧美日韩在线成人 | 日韩欧美国产一区二区三区 | 国产激情福利 | 天天色综 | 欧美一区二区三区久久精品视 | 国产高清不卡 | 国产精品久久久久久久三级 | 日本字幕在线观看 | www97影院| 成人影音| 毛片韩国| 精品久久久久一区二区国产 | 欧美人人 | 免费国产一区二区 | 美女久久久久久久久 | 久久一二| 亚洲午夜视频在线观看 | 中文字幕 在线观看 | 中文字幕一区二区三区四区 | 欧美一区二区在线观看 | 国产精品自产拍在线观看蜜 | 一级做a爰片性色毛片 | 黄色毛片一级 | 国产在视频一区二区三区吞精 | 成人午夜网站 | 亚洲欧美日韩国产综合 | 精品国产乱码久久久久久丨区2区 | 成人精品鲁一区一区二区 | 亚洲三级在线 | 日一区二区三区 |