1.确定后端返回的是一个文件
2.调用导出文件的接口,并携带相应的数据以及发送请求,获取相应的值
3.在发送请求的时候,如果访问接口需要携带token值的话,一定要和后端确定token的和变量名
4.如果你的接口请求方式是一个get的请求,可以直接将token以拼接字符串的形式进行传递
话不多说,看代码
这里是你要发送的请求
this.$http.get('/business-instock/instock/return/export', {
params: {
'buyerId': this.getSupplier.buyerId,
'status': this.documentFrom.documentType,
'access_token': this.token 这里是token值
}
})
.then((res) => {
if (res.status === 200) {
这里的地址就是你文件存放在服务器上的路径,因为是get请求,所以采用的是字符串拼接的方式,当然也要传递token的值
let excelUrl = 'http://23wz.top:9000/business-instock/instock/return/export?status=' + this.documentFrom.documentType +
'&buyerId=' + this.getSupplier.buyerId + '&access_token=' + this.token
这里是页面要跳转打开的下载页面的地址,也就是在服务器的地址
window.location.href = excelUrl
} else {
this.$message.error('导出失败')
}
})