3

我正在使用 mobx-state-tree,我想在出现错误时实际显示商店名称而不是 AnonymousModel。

例如:

const SignupModel = types
  .model({
    isUsingFacebook: false,
    birthday: '',
    timeOfBirth: types.maybeNull(types.string),
    placeOfBirth: types.maybeNull(types.string),
    gender: types.maybeNull(types.string),
    password: '',
  })

仍然给我一个错误

Error while converting {...} to AnonymousModel.

但我想得到

Error while converting {...} to SignupModel.
4

1 回答 1

4

只需将所需名称作为第一个参数传递给model方法,如下所示:

const SignupModel = types
  .model('SignupModel', {
    isUsingFacebook: false,
    birthday: '',
    timeOfBirth: types.maybeNull(types.string),
    placeOfBirth: types.maybeNull(types.string),
    gender: types.maybeNull(types.string),
    password: '',
  })
于 2019-07-30T06:06:56.783 回答