将Firebase图像URL添加到我的收藏

将Firebase图像URL添加到我的收藏,firebase,vue.js,google-cloud-firestore,firebase-storage,Firebase,Vue.js,Google Cloud Firestore,Firebase Storage,加载VueJS组件时,我正在访问以下方法: getServices () { fb.servicesCollection.get().then(querySnapshot => { this.serviceList = [] querySnapshot.forEach(doc => { const { name, icon } = doc.data() fb.storage.ref().child(icon).getDownloadURL(

加载VueJS组件时,我正在访问以下方法:

getServices () {
  fb.servicesCollection.get().then(querySnapshot => {
    this.serviceList = []
    querySnapshot.forEach(doc => {
      const { name, icon } = doc.data()
      fb.storage.ref().child(icon).getDownloadURL().then(function (url) {
        console.log(url)
      })
      this.serviceList.push({id: doc.id, name: name, icon: 'iconURL'})
    })
    this.isLoading = false
  }).catch(error => {
    console.log(error)
  })
}

我想要实现的是获取url以替换当前的“iconURL”字符串。在过去的几个小时里没有找到任何方法。请帮忙

下面的内容应该可以做到这一点。但是请注意,我无法测试它,所以它可能需要一些微调。。。您可以在评论中报告它的工作原理,必要时我们会进行更正

由于要并行执行多个对Firebase存储的getDownloadURL异步调用,因此必须使用Promise.all,因为getDownloadURL返回一个Promise,请参阅


这就是我最终得到它的原因

getServices () {
  fb.servicesCollection.get().then(querySnapshot => {
    this.serviceList = []
    querySnapshot.forEach(doc => {
      const { name, icon } = doc.data()
      fb.storage.ref(icon).getDownloadURL().then(url => {
        this.serviceList.push({id: doc.id, name: name, icon: url})
      })
    })
    this.isLoading = false
  }).catch(error => {
    console.log(error)
  })
}

谢谢你所有的努力来帮助我!!!非常感谢

你想要达到什么目标还不是100%清楚。将对象推送到serviceList时,是否要用getDownloadURL的结果替换icon的值?你从console.logurl得到了什么?正确的URL?我确实获得了图像的URL,我想在图标键上将其添加到我的服务列表中。图标是servicesCollection包含的文档字段。是这样吗?是的,是这样!我想将Firebase存储返回的url传递到serviceList集合中的我的图标键。。。我不知道该怎么做…这意味着你在servicesCollection中只有一个文档,不是吗?如果你认为我的答案对你有用,你可以投赞成票!看见谢谢
getServices () {
  fb.servicesCollection.get().then(querySnapshot => {
    this.serviceList = []
    querySnapshot.forEach(doc => {
      const { name, icon } = doc.data()
      fb.storage.ref(icon).getDownloadURL().then(url => {
        this.serviceList.push({id: doc.id, name: name, icon: url})
      })
    })
    this.isLoading = false
  }).catch(error => {
    console.log(error)
  })
}