javascript WEBPACK_IMPORTED_MODULE_1__.default集合不是函数

lhcgjxsq  于 2023-03-11  发布在  Java
关注(0)|答案(1)|浏览(216)

我还没能弄清楚这里的问题是什么。我正在使用vue 3。我试图将一个obejct添加到存储状态内部的另一个对象。我可以将其添加到firebase控制台,但唯一尚未解决的问题是如何将其作为对象中的对象添加到state.coaches的存储中。这样我就能够将对象列表显示到屏幕的视图中。

//store-coach.js
import Vue from 'vuex'
import { uid, Notify } from 'quasar'
import firebase from 'boot/firebase'

const state = {
  coaches: {
  }
}

const mutations = {
  addCoach(state, coach) {
    Vue.set(state.coaches, coach.id, coach.coach)
    }
}

const actions = {
  fbReadDataCoaches({ commit }) {
    let coachesfb = firebase.database().ref('coaches')
    //child added
    coachesfb.on('child_added',snapshot => {
      let coachfb = snapshot.val()
      let payload = {
        id: snapshot.key,
        coach: coachfb
      }
      commit('addCoach', payload)
    })
  },
  fbaddCoach({}, payload){
    let coachRef = firebase.database().ref('coaches/' + payload.id)
    coachRef.set(payload.coach, error =>{
      if(!error){
        Notify.create('Coach added!!')
      }
    })
  }
}
//index.js
import Vuex from 'vuex'
import coaches from './store-coach'
export default function (/* { ssrContext } */) {
  const Store = new Vuex.Store({
    modules: {
      coaches
    }
  })
  return Store
}

Vue.set(state.coaches, coach.id, coach.coach)被触发时,我得到的错误是

Uncaught TypeError: vuex__WEBPACK_IMPORTED_MODULE_3__.default.set is not a function

先谢了!2感谢您抽出时间!

f0brbegy

f0brbegy1#

在第一个文件(store-coach.js)中,更改:-
由─

import Vue from 'vuex'

致-

import Vue from 'vue'

由于.set方法在vue包中可用。它在vuex包中不可用,这就是为什么你会得到这个错误。文档参考。

相关问题