当我将图像上传到我的firebase存储时,如何制作进度条?

问题描述 投票:-1回答:1

我想进一步向用户显示上传了多少文件,这样他就不会退出中间上传任何人都可以帮助我如何在vue js中创建进度条

我正在使用此firebase代码来显示我使用v-model和p标签显示百分比的百分比,但没有任何效果

方法:{

uploadfiles(e) {
  var storage = firebase.storage();
  var user = firebase.auth().currentUser;
  var file = e.target.files[0];
  var path = "users/" + user.uid + "/attachments/" + Date.now() + ".jpg";
  var storageRef = storage.ref(path);
  var task = storageRef.put(file);
      task.on('state_changed');
    function progress (self, snapshot){
      var percentage = (snapshot.bytesTransferred/snapshot.totalBytes)*100;
        console.log('this is image =',percentage);
          self.progress = percentage;
           console.log(progress);
    }

    task.then(snapshot => {
      console.log("image uploaded successfully");
      //saveMessageInDatabase(newmessagedata);
      return task.snapshot.ref.getDownloadURL();
    })
    .then(url => {
      console.log("download url of image", url);
      this.username.image = url;
      console.log(this.username.image);
    })
    .catch(error => {
      // hideMessageDialog();
      console.log("image uploaded error");
    });
}

HTML

  <p>{{this.progress}}%</p>

   <progress max="100"  :style="{width: progress+'%'}" value="0"> 
 </progress> 

<div class="progress-bar" role="progressbar" v-bind:aria-valuenow="this.progress" aria-valuemin="0" aria-valuemax="100" :style="{width: this.progress+'%'}"></div>

    <input id="pic" type="file"  @change="uploadfiles">
javascript firebase vue.js firebase-storage
1个回答
1
投票
  function progress (self, snapshot){
      var percentage = (snapshot.bytesTransferred/snapshot.totalBytes)*100;
      console.log('this is image =',percentage);
      self.progress = percentage ;
    console.log(progress);
  }

this解析为progress作为self。 从this.progress = percentage ;thisfunction progress的手段。

© www.soinside.com 2019 - 2024. All rights reserved.