Yeo*_*_Li 3 javascript ecmascript-6 vue.js vuex
正在学习Vuex。我针对示例项目和文档编写了一个简单的登录页面,但是当我尝试使用动作功能时,开发人员工具只是警告我
这是我的代码:
src / views / Login.vue
handleLogin (formName) {
this.$refs[formName].validate(valid => {
if (valid) {
// to do
this.$store.dispatch('user/login', this.loginUser)
} else {
......
})
}
})
Run Code Online (Sandbox Code Playgroud)
src / store / index.js
import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/User/user'
// import info from './modules/info'
Vue.use(Vuex)
export default new Vuex.Store({
strict: false,
modules: {
user,
// info
}
})
Run Code Online (Sandbox Code Playgroud)
/src/store/modules/User/actions.js
export const userActions = {
login({commit}, loginUser) {
commit(LOGIN)
axios.post(`${ API_BASE_USER }/login`, loginUser)
.then(res => {
console.log(res)
if (res.status == 200) { commit(LOGIN_SUCCESS, res.data) }
else { commit(LOGIN_FAILURE, res.data) }
})
}
}
Run Code Online (Sandbox Code Playgroud)
/src/store/modules/User/user.js
import { userActions } from './actions'
import { userMutations } from './mutations'
export default {
namespaced: true,
state: {
token: ''
},
actions: Object.assign({}, userActions),
mutations: Object.assign({}, userMutations)
}
Run Code Online (Sandbox Code Playgroud)
我知道了。原点突变-type.jsexport const LOGIN = LOGIN
但是正确的mutation-type.js应该是 export const LOGIN = 'LOGIN'
| 归档时间: |
|
| 查看次数: |
2955 次 |
| 最近记录: |