vue下用代码打开外部链接的方式

2022-02-09 510点热度 0人点赞 0条评论

Vue下,一般是使用路由router来打开其他页面,例如:this.$router.push("/home"),有时候需要在vue里打开外部的链接。

如果在html里用a标签打开外部链接,那就直接这样做:

<a href='https://www.baidu.com' target='blank'></a>

如果在JS代码中打开

# 把当前页面替换成新页面(history历史记录中不会多一个,也就是说不能按返回来到上一个页面)
window.location.replace('https://www.baidu.com');

# 正常跳转
window.location.href = 'https://www.baidu.com';

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论