exportData () { let that = this const token = xxxxxx //获取的token axios({ method:"post", url:store.state.d2admin.api.base + '/api/key/record/export/', data:{}, headers: { 'Authorization': token }, //headers需要传token就传,不需要就不传 responseType: 'blob' //规定服务器返回值类型,可以是json,blob, text等等 }).then(res => { let binaryData = [] binaryData.push(res.data) console.log(res) const blob = new Blob(binaryData,{ type: '.xlsx' }) console.log(blob) const url1 = window.URL.createObjectURL(blob) const link = document.createElement('a') document.body.appendChild(link) link.download = "user_record.xlsx" link.href = url1 console.log(link.href) link.click() document.body.removeChild(link) window.URL.revokeObjectURL(url1) }).catch((error) => { this.$message({ message: '有问题'.message, type: 'error' }) }) },
06-13