【发布时间】:2018-07-20 01:58:00
【问题描述】:
我创建了我的商店 store/user.js
export const state = () => ({
user: {},
});
export const mutations = {
};
export const actions = {
AUTH ({commit},{email, password}){
console.log('email, password =', email, password)
}
};
export const getters = {};
组件:
<template>
<form @submit.prevent="AUTH(model)">
<input type="text" required v-model.lazy = "model.email">
<input type="password" required v-model.lazy = "model.password" >
</template>
<script>
import { mapActions } from 'vuex'
export default {
data() {
return {
model:{
email:" " ,
password:" "
}
}
},
methods: {
...mapActions(['AUTH']),
}
}
在我的组件中,我试图从一个模块中执行一个 vuex 操作,但我得到了一个错误,即使这个操作被定义了:
unknown action type: AUTH,
我对问题一无所知。
index.js
import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user.js'
Vue.use(Vuex);
const store = new Vuex.Store({
modules: {
user
}
})
【问题讨论】:
-
您能提供您创建商店的代码吗?你在使用 vuex 模块吗?
-
因为您使用的是模块,所以它将是namespaced。见this answer。
-
[nuxt] store/index.js 应该导出一个返回 Vuex 实例的方法。我错了
-
在 Nuxt 中使用模块模式时,您无需自己创建商店。相反,导出状态、getter、突变和动作。
-
我使用 nuxt 。怎么办?
标签: javascript vue.js nuxt.js