vue路由跳轉至新窗口

使用vue路由跳轉至新窗口

一、命名路由

由於router-link會被渲染會a標籤,所以在router-link標籤中添加target=‘_blank’即可在新窗口打開頁面。

<router-link to='/home' target='_blank'></router-link>

二、編程式導航跳轉

使用路由對象的resolve方法可獲取路由的href、location、route等信息,進而使用window.open()即可打開新的窗口

const {href} = this.$router.resolve(route)
window.open(href, '_blank')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章