bl4*_*sta 6 javascript vue.js vuex
我正在尝试改善vuex模块,但出现以下错误:
Uncaught Error: [vuex] getters should be function but "getters.getComments" in module "comments" is [].
Run Code Online (Sandbox Code Playgroud)
/stores/comments.js(模块)
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const state = {
comments: []
}
const getters = {
getComments: state => state.comments
}
const mutations = {
setComments(state, comments) {
state.comments = comments
}
}
const actions = {
setComments(context, data) {
context.commit('setComments', data)
}
}
export default new Vuex.Store({
state,
getters,
mutations,
actions
})
Run Code Online (Sandbox Code Playgroud)
这是我的store.js,其中包含vuex store.js的根状态
import Vue from 'vue';
import Vuex from 'vuex';
import commentsModule from './stores/comments'
Vue.use(Vuex);
const state = {
}
const getters = {
}
const mutations = {
}
const actions = {
}
export default new Vuex.Store({
state,
getters,
mutations,
modules: {
comments: commentsModule
},
actions
})
Run Code Online (Sandbox Code Playgroud)
您能帮我解决这个问题吗?尝试过但不明白是什么问题?
store实例store.jsstore实例中comment.js这是不好的首先,尝试将导出块更改comment.js为此:
export default {
state,
getters,
mutations,
actions
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1405 次 |
| 最近记录: |