In my application, I had to develop a CSV exporting function, and I managed to learn URL scheme simultaneously. I’m going to summarize them.
Suppose that you can get CSV data from an api server, you can write codes below in order to make a CSV file.
const hiddenElement = document.createElement('a');hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(res.data);hiddenElement.target = '_blank';hiddenElement.download = 'brahbrah.csv';hiddenElement.click();
Of course, there are other useful libraries, so I recommend you to use them.
I couldn’t understand the meaning of data: in href. It is URL scheme and the answer is below.
Data URLs - HTTP | MDN
Data URLs, URLs prefixed with the data: scheme, allow content creators to embed small files inline in documents. They…
This data scheme means that words following data scheme are treated as contents of files.