【发布时间】:2020-06-04 10:59:43
【问题描述】:
在我的 vue 2.6/cli 4/vuex 3.1 应用程序中,我更新了存储 vuex 中的一些数据,例如在 src/store/index.js 中:
userPropStore(context, userProp ) {
bus.$emit( 'beforeUserPropStore', userProp );
let apiUrl = process.env.VUE_APP_API_URL
Vue.http.post(apiUrl + '/personal/user-props', userProp).then(({data}) => {
let userProps= this.getters.userProps
userProps.push({
"id": data.user_props.id,
"name": data.user_props.name,
"value": data.user_props.value,
"created_at": data.user_props.created_at,
})
this.commit('refreshUserProps', userProps);
bus.$emit( 'onUserPropStoreSuccess', data );
}, error => {
console.log('context::')
console.log(context)
console.error(error)
self.$refs.userObserverForm.setErrors(error.body.errors)
});
}, // userPropStore(context, userProp ) {
并使用 vee-validate 3.2 的 ValidationProvider 我想捕获服务器错误(比如不是唯一的项目) 但我得到了错误:
index.js?4360:847 Uncaught (in promise) TypeError: Cannot read property 'userObserverForm' of undefined
上线
self.$refs.userObserverForm.setErrors(error.body.errors)
如果存储对象中有一种方法可以访问父页面,可能是上下文,它有:https://imgur.com/a/P4St8Ri ?
谢谢!
【问题讨论】:
标签: vue.js vuejs2 vuex vee-validate