需求:去文件的服务器进行下载文件
文件下载路径
解决跨域问题
配置代理找到vue.config.js
devServer: {
port: 3000,
proxy: {
'/jeecg-boot': {
target: 'http://localhost:8080', //请求本地 需要jeecg-boot后台项目
ws: false,
changeOrigin: true
},
'/haha': {
target: 'http://10.64.93.11/',
ws: false,
changeOrigin: true,
pathRewrite: {
'^/haha': ''
}
}
}
},
此时路径调用
getFile('/haha/gwptAttachment/202103/ProCustomerInfoReportApprovalV7/93367c3d-ae47-4992-afa4-b962c05de2be/需求配置报告.docx')
说明
pathRewrite中的^/haha会把路径中的/haha替换为空串,也可以删除pathRewrite,路径修改为
'/gwptAttachment/202103/ProCustomerInfoReportApprovalV7/93367c3d-ae47-4992-afa4-b962c05de2be/需求配置报告.docx'
本文档介绍如何在Vue项目中处理文件下载的跨域问题,通过配置vue.config.js的devServer代理实现。示例中展示了针对'http://10.64.93.11'服务器的代理设置,并提供了调用示例。通过pathRewrite,可以将'/haha'路径重写,从而避免跨域限制。

3387

被折叠的 条评论
为什么被折叠?



