Project requirements, download an Excel file, I put the file in the code, add a button and click to download, because it is a very small file, there is no need for the back end to do, the simplest way is to use a label

<a href=" download XXX. XLSX "download=" XLSX ">Copy the code

For example, TXT, PNG and JPG files supported by the browser will not be downloaded. Instead, they will be opened directly. In this case, you need to add an attribute “Download” to the A TAB.

Here comes the key: the location of the file and the address of the file are the two biggest holes.

1. Location of files:

When we wrote the vUE, the code was stored in the SRC folder, but the files to be downloaded were not stored in the SRC folder, they were stored in the static folder of the same class, such as the public folder

The static folder is written in others’ article, but mine doesn’t work, I don’t know why.

Ii. Reference to file address:

The required download path is relative to the index. HTML file path otherwise the download file is not found.

The path is relative to the file path of index.html. The path is relative to the file path of my code, such as… /.. /.. / public/XXX. XLSX. It turns out that this is not a path relative to index.html,

This is my code, and I realize that the file is the same as index.html, so the reference path is directly:

Href ="./ user information template. XLSX"Copy the code

The two pits are over and files can be downloaded normally.

As for the file path and download file name, there will be errors in Chinese, I have no problem, I don’t know whether yours will, this is also a problem to consider.