vue js打开外部链接网页 去除前缀 本地localhost方法

window.open(‘baidu.com’) 总是会发现跳转的是 localhost:xxxx/baidu.com,显然不是我们要的效果,
在url前面+‘//’ 就可以了
使用window.open(’//’+‘baidu.com’)

 

2022.07.14更新
用上述方法后发现出现了另一种情况,如果我的地址是https://www.baidu.com/,用上述方法打开,会变成https//www.baidu.com。具体原因未知,但是找到了两种解决方案,记录一下,都是基于a标签
1.在网页内直接嵌入a标签

<el-table-column label="详情" align="center">
        <template slot-scope="scope">
          <el-button type="text" >
            <a :href="scope.row.url" target="_blank">查看链接</a>
          </el-button>
        </template>
</el-table-column>

2.js生成a标签

const element = document.createElement('a');
element.href = url
element.target = '_blank'
element.click()

 

posted @ 2022-07-13 14:54  smil、梵音  阅读(1192)  评论(0编辑  收藏  举报