Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fApi.fields()无法获取表单字段 #302

Closed
canomh opened this issue Feb 24, 2021 · 8 comments
Closed

fApi.fields()无法获取表单字段 #302

canomh opened this issue Feb 24, 2021 · 8 comments

Comments

@canomh
Copy link

canomh commented Feb 24, 2021

2.5.0-alpha.2

element-ui

2.12.0

在表单加载完成后,使用fApi.fields()函数无法获取表单字段,返回值为[]。(通过fApi.form验证,表单实际有字段)

在全局配置中,使用mounted属性,在函数中输出fApi.fields()。(规则文件较大,不便展示)
当将规则简化为如下形式后,仍存在此问题。

[
    {
      type: 'input',
      field: 'projectBase-projectNum',
      title: '选题序号'
    },
    {
      type: 'input',
      field: 'projectBase-projectName',
      title: '项目名称'
    }
]

使用fApi.fields()函数可以获取表单字段

@xaboy
Copy link
Owner

xaboy commented Feb 24, 2021

感谢反馈 ,我检查一下

@xaboy
Copy link
Owner

xaboy commented Feb 24, 2021

@canomh 我这边没有复现,在 option.mounted 中能正常获取到 fields. 在线示例

@canomh
Copy link
Author

canomh commented Mar 8, 2021

非常感谢,我再看一下具体原因。

@canomh canomh closed this as completed Mar 8, 2021
@canomh
Copy link
Author

canomh commented Mar 9, 2021

@xaboy 你好,
由于我的表单规则文件较多,采用了动态import的方式加载rule,在使用此方式的基础上,mounted函数中无法正常输出fApi.fields()的值,即便对rule的加载使用了async和await(fields的使用等待rule加载的完成),仍然无法正确获取fields。
该方法在2.5.0版本之前是生效的,请问应该如何处理来适配2.5.0版本?

@canomh canomh reopened this Mar 9, 2021
@xaboy
Copy link
Owner

xaboy commented Mar 9, 2021

我这边先检查一下

@canomh
Copy link
Author

canomh commented Mar 9, 2021

相关代码如下

  // 规则加载函数
  let module = await import('@/utils/form/rule/'+ ruleName)
  const ruleFunc = module.default
  const ruleArray = ruleFunc()
  _.each(ruleArray, function(value) {
    rule.push(value)
  })

  // 调用规则加载函数
  this.ruleLoaded = dispatch(this.ruleName, this.rule);

  // 使用表单fields的值
  await this.ruleLoaded 
  let fields = this.fApi.fields()
  console.debug('使用表单属性', fields)

@xaboy
Copy link
Owner

xaboy commented Mar 10, 2021

2.5.0-alpha.5 版本优化了下 你再试试

@canomh
Copy link
Author

canomh commented Mar 10, 2021

谢谢!经过验证,此问题已解决。

@canomh canomh closed this as completed Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants