springboot+vue下载文件一篇就够了

前台代码

export function downLoad(id) {
  var url = baseURL + `/api/admin/system/promotion/downLoad/${id}`
    axios({
      method: 'get',
      url: url,
      responseType: 'blob',
      headers: { 'Authori-Zation': getToken() }
    }).then(async (res) => {
      // 从 Content-Disposition 头部解析文件名  
    const contentDisposition = res.headers['content-disposition'];  
    let filename = '';  
    if (contentDisposition && contentDisposition.indexOf('attachment') !== -1) {  
      const matches = /"([^"]*)"/.exec(contentDisposition);  
      if (matches != null && matches[1]) {  
        filename = matches[1];  
      }  
    }  
  
    // 如果文件名未解析到&#

你可能感兴趣的:(一篇就够了,vue.js,spring,boot,前端)