vue 项目中在新标签页打开项目,如果已存在打开过的则直接进入,没有才打开一个新的-----笔记

利用a标签的target属性,把target设置成具体的页面跳转值,如果浏览器已经有标签页的地址是#/companyIndex,则点击上面的链接并不会打开新窗口,是直接进入已经打开的#/companyIndex;如果浏览器中没有地址是#/companyIndex的标签页,则此时target属性的行为表现类似'_blank',会打开一个新的#/companyIndex标签页 ,有两种写法

1.直接在html页面中写死

<a class="product_content1_item_title pointer" target="#/companyIndex" href="#/companyIndex" >中央门户</a>

2.写在js中,通过$router.resolve()获取页面地址,并且还可以自己需要的逻辑

<a class="product_content1_item_title pointer" target="#/companyIndex" id="zhongyang"  @click="jumpToEvent('zhongyang','companyIndex')">中央门户</a>

 methods:{
      jumpToEvent(id,path){
        
        const news = this.$router.resolve(path);
        console.log(news.href);
        // window.location.href = news.href;// 在当前标签页打开
        // window.open(news.href,'_blank')// 打开新标签页
        // window.open(news.href)// 打开新标签页
        let a = document.getElementById(id);
        a.setAttribute("href",news.href);
        console.log(a)
      }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值