【问题标题】:Mobx-state-tree: how to rename AnonymousModel to the store nameMobx-state-tree:如何将 AnonymousModel 重命名为商店名称
【发布时间】:2019-07-28 01:41:04
【问题描述】:

我正在使用 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.

【问题讨论】:

    标签: javascript mobx mobx-state-tree


    【解决方案1】:

    只需将所需名称作为第一个参数传递给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: '',
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-25
      • 2019-11-26
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多