0
我使用這種結構的形式存儲和驗證:https://medium.com/@KozhukharenkoN/react-form-validation-with-mobx-8ce00233ae27MobX:將數據傳輸到店從另一個存儲
有一家商店的形式:
import { observable, action, computed } from 'mobx'
import FormStore from './FormStore'
import UserStore from 'stores/UserStore'
class SettingsFormStore extends FormStore {
@observable
form = {
fields: {
email: {
value: UserStore.email,
defaultValue: UserStore.email,
error: null,
rule: 'required|email'
},
},
meta: {
isValid: true,
error: null,
},
}
}
export default new SettingsFormStore()
存在stor用戶:
import { observable, action, computed } from 'mobx'
import * as UserAPI from 'api/UserAPI'
class UserStore {
@observable id
@observable email
constructor() {
this.load()
}
@action setValues(values) {
this.id = values.id
this.email = values.email
}
@action removeValues() {
this.id = null
this.email = null
}
load() {
UserAPI.getMe()
.then(result => {
this.setValues(result.user)
})
}
}
export default new UserStore()
在表單組件我收到的電子郵件從商店:
const email = SettingsFormStore.form.fields.email.value
但電子郵件某種原因undefied,雖然UserStore.email保持價值...
但有問題:如何使用多個參數來自UserStore的rs在一個反應? – Max