import Vue from 'vue'
import Vuex from 'vuex'
import { createModule } from 'vuex-toast'
import 'vuex-toast/dist/vuex-toast.css'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
toast: createModule({
dismissInterval: 80000
}),
app: {
state: {
raps: [],
},
getters: {
getRaps () {
return store.state.app.raps
},
getRapsFiltered (state, getters) { //error happens in this func
return getters.getRaps.filter(state.filterFunc)
}
}
}
}
})
export default store
我收到错误消息“Uncaught TypeError:null不是函数”。 如何在getter中调用getter函数? 这段代码似乎有什么问题?
答案 0 :(得分:0)
您可以使用传递给getter函数的getters参数来调用getter
const getters = {
calculateItemTax: () => item => {
return item.item_tax
},
orderTax: (state, getters) => {
state.items.forEach(item => {
taxAmount += getters.calculateItemTax(item)
})
return taxAmount
},
}