我使用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
})
答案 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
})