vue local file download

The file is placed in public
scheme one:

                <a-button
                  type="primary"
                  @click="downloadMeaTemp"
                >
          模板下载
                </a-button>
   download () {
    
    
      axios.get('/template.xlsx', {
    
       //静态资源文件夹public            
        responseType: 'blob',
      }).then(response => {
    
    
        const url = window.URL.createObjectURL(new Blob([response.data]));
        const link = document.createElement('a');
        let fname = '模板.xlsx';
        link.href = url;
        link.setAttribute('download', fname);
        document.body.appendChild(link);
        link.click();
         }).catch(error => {
    
    
        console.log('error:' + JSON.stringify(error))
      });
    },

Option II:

<a
href="/template.xlsx"
download="模板.xlsx"
style="marginleft: 10px"
>
<a-button type="primary" style="margin-right: 15px">
模板下载
</a-button>
</a> 
                

Guess you like

Origin blog.csdn.net/q249859693/article/details/127462079