【发布时间】:2018-08-26 03:44:28
【问题描述】:
我的脚本 ajax 是这样的:
this.$store.dispatch('changePassword', {password})
.then((response) => {
console.log('resp')
console.log(response)
})
.catch(error => {
console.log('er')
console.log(error)
});
我使用 vue 组件/vuex 商店
当脚本运行时,选项卡控制台上的结果如下:
如果我在标签网络中签入标签响应,结果如下:
我想获得价值:
旧密码确认不匹配。
我在响应/错误上有 console.log,但我没有找到对象
如何获得价值?
更新:
我的 vuex 模块是这样的:
import { set } from 'vue'
import users from '../../api/users'
import * as types from '../mutation-types'
// initial state
const state = {
addStatusChangePassword: null
}
// getters
const getters = {
changePasswordStatus: state => state.changePasswordStatus,
}
// actions
const actions = {
changePassword ({ dispatch,commit,state },{password})
{
return users.changePassword(password,
data => {
commit(types.CHANGE_PASSWORD_SUCCESS)
},
errors => {
commit(types.CHANGE_PASSWORD_FAILURE)
}
)
}
}
// mutations
const mutations = {
[types.CHANGE_PASSWORD_SUCCESS] (state){
state.addStatusChangePassword = 'success'
},
[types.CHANGE_PASSWORD_FAILURE] (state){
state.addStatusChangePassword = 'failure'
}
}
export default {
state,
getters,
actions,
mutations
}
我的 vuex api 是这样的:
import Vue from 'vue'
export default {
// api to change password
changePassword (password, cb, ecb = null) {
return axios.post('/member/profile/change-password', password).then(
(resp) => {
return resp.data;
},
(resp) => {
return resp.data;
}
);
}
}
【问题讨论】:
-
显示
changePassword操作的代码 -
您的操作似乎发现了错误。不看代码很难知道发生了什么。
-
@acdcjunior 看看我的问题。我已经更新了
-
@Mark_M 看看我的问题。我已经更新了
标签: javascript jquery ajax vue.js vue-component