在mutation.js中导出一系列突变

时间:2017-09-22 14:28:45

标签: javascript vue.js vuex

我使用vuexfire将我的vuex状态绑定到firebase,为此,我需要将他们的{ firebaseMutations }放入商店的突变中。但是,我的突变位于mutations.js文件中。我尝试输出这样的突变:

export { firebaseMutations } from 'vuexfire'

但出现此错误:Uncaught Error: [vuex] mutations should be function but "mutations.firebaseMutations" is {}.

我尝试了很多

的变体
export * from { firebaseMutations }

但它们都不起作用。

有没有办法可以使用对象扩展运算符或export从我的mutations.js导出这些?

import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
import * as mutations from './mutations'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({
  state: {
    // ...
  },
  getters,
  mutations,
  actions,
  strict: debug
})

1 个答案:

答案 0 :(得分:1)

我通过在两者上使用对象扩展运算符来修复它:

import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
import * as mutations from './mutations'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({
  state: {
    // ...
  },
  getters,
  mutations: {
     ...mutations,
     ...firebaseMutations
  },
  actions,
  strict: debug
})