最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue-router跳轉(zhuǎn)方式的區(qū)別解析

 更新時(shí)間:2022年12月14日 09:52:26   作者:_曾經(jīng)滄海難為水  
在Vue中,router-link稱(chēng)為聲明式路由,:to綁定為跳轉(zhuǎn)的目標(biāo)地址,一種是通過(guò)name,另一種是path,這篇文章主要介紹了vue-router跳轉(zhuǎn)方式的區(qū)別,需要的朋友可以參考下

一、router-link(聲明式路由,在頁(yè)面中調(diào)用)

在Vue中,router-link稱(chēng)為聲明式路由,:to綁定為跳轉(zhuǎn)的目標(biāo)地址,一種是通過(guò)name,另一種是path。
1.1 路由不帶參數(shù)

 <router-link :to="{ name: 'word' }">路由name方式跳轉(zhuǎn)首頁(yè)</router-link>
      <router-link :to="{ path: '/word' }">路由path方式跳轉(zhuǎn)首頁(yè)</router-link>

1.2 路由帶參數(shù)跳轉(zhuǎn)
路由參數(shù)的傳遞主要有兩種方式一種是params,另一種是query,主要區(qū)別:

1. params傳參的參數(shù)不會(huì)顯示在跳轉(zhuǎn)的URL中,query傳參的參數(shù)會(huì)顯示在URL中。

2. params所傳的參數(shù)通過(guò)this.$route.params.參數(shù);獲取,query所傳的參數(shù)通過(guò)this.$route.query.參數(shù) 獲取

3. 因?yàn)閜arams所傳遞的參數(shù)不顯示在URl中,所以在路由跳轉(zhuǎn)時(shí)推薦params方式進(jìn)行傳參

4. 都不能傳對(duì)象和數(shù)組引用類(lèi)型數(shù)據(jù),只能傳字符串類(lèi)型數(shù)據(jù)

<router-link :to="{ name: 'home', params: { key: '1', value: '跳轉(zhuǎn)' } }">路由name,params方式跳轉(zhuǎn)首頁(yè)</router-link>
     <router-link :to="{ name: 'home', query: { key: '1', value: '跳轉(zhuǎn)' } }">路由name,query方式跳轉(zhuǎn)首頁(yè)</router-link>
     
     <router-link :to="{ path: '/home', params: { key: '1', value: '跳轉(zhuǎn)' } }">路由path,params方式跳轉(zhuǎn)首頁(yè)</router-link>
     <router-link :to="{ path: '/home', query: { key: '1', value: '跳轉(zhuǎn)' } }">路由path,query方式跳轉(zhuǎn)首頁(yè)</router-link>

二、this.$router.push() (在函數(shù)里面調(diào)用)

2.1不帶參數(shù)跳轉(zhuǎn)

this.$router.push({ path: '/home'});
this.$router.push({ name: 'home'});

2.2帶參數(shù)跳轉(zhuǎn)

 <a-button type="primary" @click="goTo">路由name方式跳轉(zhuǎn)</a-button>
  goTo() {
    this.$router.push({ name: 'home', params: { a: '1', b: '2' } });//推薦用params傳參方式
    this.$router.push({ name: 'home', query: { a: '1', b: '2' } });
  }

三、this.$router.resolve()打開(kāi)新窗口跳轉(zhuǎn)

3.1通過(guò)path形式跳轉(zhuǎn)

goTo() {
    let routeData = this.$router.resolve({
      path: '/home',
    });
    window.open(routeData.href, '_blank');
  }

3.2通過(guò)name形式跳轉(zhuǎn)

goTo() {
    let routeData = this.$router.resolve({
      name: 'home',
    });
    window.open(routeData.href, '_blank');
  }

到此這篇關(guān)于vue-router跳轉(zhuǎn)方式的區(qū)別的文章就介紹到這了,更多相關(guān)vue-router跳轉(zhuǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

禄丰县| 武山县| 泊头市| 获嘉县| 河津市| 华蓥市| 镇坪县| 微博| 吐鲁番市| 武功县| 高邮市| 巴彦淖尔市| 贵州省| 阳东县| 昆山市| 赤壁市| 兴海县| 伽师县| 桃江县| 棋牌| 紫金县| 从江县| 怀远县| 华宁县| 鹤山市| 无为县| 天门市| 宜都市| 山东省| 博罗县| 镇远县| 韶山市| 大丰市| 嘉义市| 德保县| 平湖市| 晋城| 合山市| 东阿县| 绍兴市| 桃园县|