我想进一步向用户显示上传了多少文件,这样他就不会退出中间上传任何人都可以帮助我如何在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">
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 ;
,this
是function progress
的手段。