vue访问外部链接会拼接默认路径的问题

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

posted @ 2019-08-19 17:18  penglb  阅读(2586)  评论(0编辑  收藏  举报