The front end directly downloads according to the url returned by the back end

As shown in the figure, the backend directly returns a download address, which can be downloaded directly by opening this address in the browser.
insert image description here
The requirement is to download by clicking a button in the front-end code. You need to bind a click event to the button. The specific download implementation code is as follows:

    download_history(download_addr) {
    
    
      var elemIF = document.createElement('iframe')
      elemIF.src = download_addr
      elemIF.style.display = 'none'
      document.body.appendChild(elemIF)
      // 防止下载两次
      setTimeout(function() {
    
    
        document.body.removeChild(elemIF)
      }, 1000)
    },

Then you can see that the download is successful at the bottom of the computer!
insert image description here

Guess you like

Origin blog.csdn.net/changyana/article/details/130504107