Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

vue.js - browser extension - download multiple JSZip unzipped files

I'm using JSZip in my vue browser extension. I've created a function to read zip files and I'm able to get the content of the zip. I want to give to the user the ability to download multiple files after selecting them but I'm not able to achieve this. Here is the code

Inside the template code I'm using a v-for to generate a list of the files that are inside the opened zip file

        <ul class="list-group list-group-flush pt-5 overflow-auto">
          <li class="list-group-item" v-for="(file, i) in filesList" :key="i">
            <small class="float-start">{{ file }}</small>
            <input class="form-check-input float-end" type="checkbox" ref="selectedFile">
          </li>
        </ul>

Inside the <script> tag in the methods section I have this two methods

  methods: {
    handleFiles(e) {
      e.dataTransfer.files.forEach( (file) => {
        JSZip.loadAsync(file).then( (zip) => {
          zip.forEach( (relativePath, zipEntry) => {
            this.filesList.push(relativePath);
            this.files.push(zipEntry);
          });
        });
      });
    },
    downloadSelectedFiles() {
      this.files.forEach( (file) => {
        JSZip.file(file).async('blob').then( (data) => {
          console.log(data);
        });
      });
    }
  }

How I can call the chrome.downloads.download method to let the user download all the selected files? I've tried to use the $refs but it will only select one checkbox, also I don't know how to convert the object passed from JSZip to the method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...