vue路由跳轉(zhuǎn)打開(kāi)新窗口

需求

因?yàn)槟承┰?,某個(gè)頁(yè)面的加載需要很長(zhǎng)時(shí)間。為了不讓用戶重新加載,再次等待很長(zhǎng)時(shí)間,決定當(dāng)從這個(gè)頁(yè)面跳轉(zhuǎn)其他頁(yè)面時(shí),打開(kāi)一個(gè)新窗口。

編程時(shí)導(dǎo)航

使用路由對(duì)象的resolve方法解析路由,可以得到location、router、href等目標(biāo)路由的信息。得到href就可以使用window.open開(kāi)新窗口了。

當(dāng)頁(yè)面有一個(gè)跳轉(zhuǎn)時(shí)

const { href } = this.$router.resolve({
    name: "router-name",
    query: {
        id: 1
    }
});
window.open(href, '_blank');

當(dāng)頁(yè)面有多個(gè)跳轉(zhuǎn)時(shí)

let routeOne = this.$router.resolve({
    name: "router-one",
    query: {
        id: 1
    }
 });
 window.open(routeOne.href, '_blank');

 let routeTwo = this.$router.resolve({
    name: "router-two",
    query: {
        id: 1
    }
 });
 window.open(routeTwo.href, '_blank');

<router-link>標(biāo)簽

<router-link tag="a" 
             target="_blank"
             :to="{ name: 'router-name', query: {id: 1} }">
</router-link>

網(wǎng)站導(dǎo)航

網(wǎng)站導(dǎo)航

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容