vue訪問后端返回的路徑,直接下載文件,后端路徑格式與 www.baidu.com 類似,
用原生 js 解決發現路徑前拼接上了默認路徑,實際跳轉的路徑為 localhost:8080/www.baidu.com 與預期不符合。
參照別人的解決辦法:針對我自己的情況,要在路徑前面加上 http://
data() { return { url: '', }; }, methods: {
getURL(){
axios.post(params,url).then((res)=>{
this.url = 'http://' + res (前面拼接上一個http 這個很關鍵,后端返回的路徑沒有加協議,否則無法訪問,提示私密鏈接之類的)
})
}, jump(){ window.location.href = this.url; }, },
參考鏈接:https://blog.csdn.net/tom_wong666/article/details/85938880