9951 explained code solutions for 126 technologies


vue.jsHow do I download a zip file using Vue.js?


To download a zip file using Vue.js, you can use the JSZip library.

First, include the library in your project by adding the following code to the <head> section of your HTML file:

<script src="https://stuk.github.io/jszip/dist/jszip.js"></script>

Then, you can use the following code to download the zip file:

import JSZip from 'jszip';

let zip = new JSZip();

// Add files to the zip
zip.file("Hello.txt", "Hello World\n");

// Generate the zip file asynchronously
zip.generateAsync({type:"blob"})
.then(function(content) {
    // see FileSaver.js
    saveAs(content, "example.zip");
});

The code above will generate a zip file containing the file Hello.txt with the content Hello World and download it as example.zip.

Helpful links

Edit this code on GitHub