简体   繁体   English

TypeError:无法读取未定义的firebase和vuex的属性“ 0”

[英]TypeError: Cannot read property '0' of undefined firebase and vuex

I'm using vuex action, it happen when I try to get the urlof the uploaded image everything is fine and the image is saved in firebase, but I can't get the downloadUrl and add it the reference of downloadurl to my meetup database 我正在使用vuex操作,当我尝试获取上载图像的url时一切都很好,并且图像已保存在firebase中,但是我无法获得downloadUrl并将其对downloadurl的引用添加到我的metup数据库中

My code look like this 我的代码看起来像这样

actions: {
    createMeetup ({commit, getters}, payload) {
      const meetup = {
        title: payload.title,
        location: payload.location,
        description: payload.description,
        date: payload.date.toISOString(),
        creatorId: getters.user.id
      }
      let imageUrl
      let key
      firebase.database().ref('meetups').push(meetup)
        .then((data) => {
          key = data.key
          return key
        })
        .then(key => {
          const filename = payload.image.name
          const ext = filename.slice(filename.lastIndexOf('.'))
          return firebase.storage().ref('meetups/' + key + '.' + ext).put(payload.image)
        })
        .then(fileData => {
          console.log(fileData)
          imageUrl = fileData.metadata.downloadURLs[0]
          return firebase.database().ref('meetups').child(key).update({imageUrl: imageUrl})
        })
        .then(() => {
          commit('createMeetup', {
            ...meetup,
            imageUrl: imageUrl,
            id: key
          })
        })
        .catch((error) => {
          console.log(error)
        })
    }

holla i ask i answer my self i got the solution thanks guys for not answering 霍拉,我问我回答自己,我得到了解决方案,谢谢你们不回答

createMeetup ({commit, getters}, payload) {
          const meetup = {
            title: payload.title,
            location: payload.location,
            description: payload.description,
            date: payload.date.toISOString(),
            creatorId: getters.user.id
          }
          let imageUrl
          let key
          firebase.database().ref('meetups').push(meetup)
            .then((data) => {
              key = data.key
              return key
            })
            .then(key => {
              const filename = payload.image.name
              const ext = filename.slice(filename.lastIndexOf('.'))
              return firebase.storage().ref('meetups/' + key + '.' + ext).put(payload.image)
            })
            .then(snapshot => {
              return new Promise((resolve, reject) => {
                snapshot.ref.getDownloadURL().then(url => {
                  snapshot.downloadURL = url
                  resolve(snapshot)
                })
              })
            })
            .then((snapshot) => {
              imageUrl = snapshot.downloadURL
              return firebase.database().ref('meetups').child(key).update({imageUrl: imageUrl})
            })
            .then(() => {
              commit('createMeetup', {
                ...meetup,
                imageUrl: imageUrl,
                id: key
              })
            })
            .catch((error) => {
              console.log(error)
            })
        },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vuex 返回“TypeError:无法读取未定义的属性‘getters’” - Vuex returning “TypeError: Cannot read property 'getters' of undefined” Firebase TypeError:无法读取未定义的属性“ ac” - Firebase TypeError: Cannot read property 'ac' of undefined Firebase TypeError:无法读取未定义的属性“val” - Firebase TypeError: Cannot read property 'val' of undefined 类型错误:无法读取未定义的属性“长度”- Firebase - TypeError: Cannot read property 'length' of undefined - Firebase FIREBASE警告:TypeError:无法读取未定义的属性“ then” - FIREBASE WARNING: TypeError: Cannot read property 'then' of undefined 无法读取未定义的属性“电子邮件”; firebase auth(); 使用 Vuex - Cannot read property 'email' of undefined; firebase auth(); using Vuex ReactJS。 Firebase。 TypeError:无法读取未定义的属性“setState” - ReactJS. Firebase. TypeError: Cannot read property 'setState' of undefined 用 FIREBASE 表达我得到 TypeError: Cannot read property 'trim' of undefined - Express with FIREBASE I get TypeError: Cannot read property 'trim' of undefined Firebase未捕获的TypeError:无法读取未定义的属性'forEach' - Firebase Uncaught TypeError: Cannot read property 'forEach' of undefined firebase onAuth()抛出:TypeError无法读取未定义的属性'auth' - firebase onAuth() throwing: TypeError cannot read property 'auth' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM