【问题标题】:vuex module namespace not found in mapActions(): taskModule/?在 mapActions() 中找不到 vuex 模块命名空间:taskModule/?
【发布时间】: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


【解决方案1】:

既然你有一个模块,你需要改变:

export default createStore({
  state: {    
    taskModule
  },
})

收件人:

export default createStore({
  modules: {    
    taskModule
  },
})

https://next.vuex.vuejs.org/guide/modules.html

【讨论】:

  • GOAT(为什么我从不仔细阅读文档)
猜你喜欢
  • 2020-09-27
  • 1970-01-01
  • 2020-03-29
  • 2019-01-21
  • 2020-07-24
  • 2020-07-14
  • 2019-02-26
  • 2018-05-27
  • 2020-05-07
相关资源
最近更新 更多