【发布时间】:2021-05-17 04:16:43
【问题描述】:
您好,我的应用程序开始增长,所以我决定(第一次)调用 vuex,但是当我调用模块的操作/突变时,我无法让它工作
我的任务模块
const state = () => ({
newTask : false,
tasks: []
})
const getters = {}
const actions = {
test() {
console.log('EYOOO IT WORKSS')
},
}
const mutations = {}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}
我的商店
import { createStore } from 'vuex'
import taskModule from '../store/modules/tasks'
export default createStore({
state: {
taskModule
},
})
我的组件 js
export default {
components: {
Button,
TaskList,
NewTask,
},
computed: mapState({
newTask: (state) => state.taskModule.state().newTask,
tasks: (state) => state.taskModule.state().tasks,
}),
methods: {
...mapActions("taskModule",["test"]),
newTask(val) {
this.$store.dispatch("taskModule/test")
console.log(val);
},
},
};
当我调用 newTask 时出现错误
【问题讨论】:
-
你有一个计算方法和一个名为
newTask的方法 -
哎呀真的!我改变了它......但我仍然得到错误
标签: vue.js components vue-component state vuex