Without further ado, let’s get right to the front-end code
` axios ({method: “post”, url: ‘http://localhost:19090/exportUser’, / / this is the address of the request params: {/ / this is the parameters of the request email: this.email, startRegisterDate: this.registerStartTime, endRegisterDate: this.registerEndTime }, responseType: ‘blob’ }).then((res) => { console.log(res) const link = document.createElement(‘a’) let blob = new Blob([res.data],{type: ‘application/vnd.ms-excel’}); link.style.display = ‘none’ link.href = URL.createObjectURL(blob); let num = ” for(let i=0; i < 10; i++){ num += Math.ceil(Math.random() * 10) } link.setAttribute(‘download’, Users’ _ ‘+ num +. XLS’). The document body. The appendChild (link) link. Click (). The document body. RemoveChild (link)}). The catch (error = > {
console.log(error) })`
It is important to note that the AXIos request adds a responseType: ‘blob’ configuration
My project needs the sessionId in the request header, so I need to use the above method
If it is a get request, do not need extra parameter request header, direct window. The location. The href = ‘http://localhost:19090/exportUser? Email =’+email+”&start=”+start