我有行动
store.js - vuex
打电话
signUserIn
. SignUserIn方法只是
http post
请求。我已经进口了
Vue-Resource
在里面
store
文件:
import VueResource from 'vue-resource'
,
Vue.use(VueResource)
也在
main.js
-
store.js
已导入。在我的
SignIn.vue
第一部分调度
SignIn
行动。我得到一个错误:
Cannot read property 'post' of undefined
. 我的导入或代码有什么问题?
行动:
signUserIn ({commit, getters}, payload) {
let data = {
_email: payload.email,
_password: payload.password
}
let that = this
that.$http.post(
'url',
data,
{ channel: 'default' },
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
).then(response => {
const newUser = {
email: payload.email,
login: payload.login,
cart: []
}
commit('setUser', newUser)
}, error => {
console.error(error);
});
}
突变:
setUser (state, payload) {
state.user = payload;
}