問題
vue 跳轉外部鏈接問題,當跳轉的時候會添加在當前地址后面
var url = 'www.baidu.com'
//跳轉1
window.localtion.href = url
//跳轉2
window.history.pushState(url);
window.history.replaceState(url);
//跳轉3
window.open(url,"_blank");
//跳轉4
var a = document.createElement("a");
a.setAttribute("href", "www.baidu.com");
a.setAttribute("target", "_blank");
a.click();
http://192.168.0.139:8080/#/
http://192.168.0.139:8080/www.baidu.com#/
這時將 url 前面添加響應的 (http:// 或 https://)
var p = window.location.protocol;
var a = document.createElement("a");
a.setAttribute("href", `${p}//www.baidu.com`);
a.setAttribute("target", "_blank");
a.click();
document.getElementsByTagName("body")[0].appendChild(a);