我正在使用此代码更新图像并获取 URL,但无法获取 URL。
好像return一些是因为可以进入return的promise。
我从这里得到这个代码:https : //gist.github.com/CristalT/2651023cfa2f36cddd119fd979581893
该代码适用于另一个用户,所以我认为问题出在依赖性或数据库规则中。
我被认证了。
<template>
<div>
<input type="file" multiple accept="image/*" @change="detectFiles($event.target.files)">
<div class="progress-bar" :style="{ width: progressUpload + '%'}">{{ progressUpload }}%</div>
</div>
</template>
<script>
import { storage } from '../firebase'
export default {
data () {
return {
progressUpload: 0,
file: File,
uploadTask: '',
downloadURL: ''
}
},
methods: {
detectFiles (fileList) {
Array.from(Array(fileList.length).keys()).map( x => {
this.upload(fileList[x])
})
},
upload (file) {
this.uploadTask = storage.ref('imagenes/articulos').put(file);
this.uploadTask.then(snapshot => {
this.downloadURL = this.uploadTask.snapshot.downloadURL;
this.$emit('url', this.downloadURL)
}) …Run Code Online (Sandbox Code Playgroud)