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

自定义表单组件一直报warning #1076

Closed
1 task done
mkanako opened this issue Aug 11, 2019 · 11 comments
Closed
1 task done

自定义表单组件一直报warning #1076

mkanako opened this issue Aug 11, 2019 · 11 comments
Labels
Accept You are right, we should do that bug outdated

Comments

@mkanako
Copy link

mkanako commented Aug 11, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.3.13

Environment

Chrome 75

Reproduction link

https://vue.ant.design/components/form-cn/#components-form-demo-customized-form-controls

Steps to reproduce

对input做一层简单封装

<template>
  <div>
    <a-input
      v-bind="$attrs"
      :value="input"
      @change="triggerChange"
    />
  </div>
</template>
<script>
export default {
  name: 'CustomInput',
  props: {
    value: {
      type: String,
      default: '',
    },
  },
  inheritAttrs: false,
  data () {
    return {
      input: this.value,
    }
  },
  watch: {
    value (val) {
      this.input = val
    },
  },
  methods: {
    triggerChange (val) {
      this.input = val
      this.$emit('change', val)
    },
  },
}
</script>
使用
<a-form-item label="CustomInput">
<CustomInput
    v-decorator="[
    'CustomInput',
    {
        rules: [{ required: true, message: '请输入' }]}
    ]"
/>
</a-form-item>

What is actually happening?

控制台报warning:

CustomInput default value can not collect, please use option.initialValue to set default value.

按照提示去设置initialValue,还是有问题

<a-form-item label="CustomInput">
<CustomInput
    v-decorator="[
    'CustomInput',
    {
        initialValue:'',//空值也不行,必须不为空才行??
        rules: [{ required: true, message: '请输入' }]}
    ]"
/>
</a-form-item>

What is expected?

希望能像input一样,不需要设置initialValue也正常

@sendya
Copy link
Member

sendya commented Aug 11, 2019

props: {
    value: {
      type: String,
-      default: '',
    },
  },

去除。
这个问题会在之后的版本优化,设置了 default 也不会在提示

@mkanako
Copy link
Author

mkanako commented Aug 12, 2019

这样是可以了,期待优化下~

@tangjinzhou
Copy link
Member

1.3.13已经优化了的,还有问题? @mkanako

@mkanako
Copy link
Author

mkanako commented Aug 15, 2019

@tangjinzhou
1.3.13是解决了这个issue吧#915
但我看报的warning不一样,目前确实还是有问题

@tangjinzhou
Copy link
Member

哦哦 这个是提醒 form 无法收集内部的默认值,如果有默认值,可以使用 initialValue,这样也不会报warning

@mkanako
Copy link
Author

mkanako commented Aug 15, 2019

@tangjinzhou

initialValue:'',//空值也不行,必须不为空才行??

initialValue如果是空字符串照样warning啊

@tangjinzhou tangjinzhou added Accept You are right, we should do that bug labels Aug 15, 2019
@mkanako
Copy link
Author

mkanako commented Aug 15, 2019

另外我拿我上面的例子来说,我用input封装了个组件出来
我希望这个组件基本行为表现跟input一致
使用者在使用这个组件的时候能像input一样无需设置initialValue也正常

@tangjinzhou
Copy link
Member

不设置这个事情,目前有点困难 所以加了提醒 😓

tangjinzhou added a commit that referenced this issue Aug 15, 2019
@zijingsong
Copy link

还是有问题,a-form-item里嵌套一个自定义组件,当设置
value: { type: String, default: '' },
时报错:initialValue is not defined。
注释掉后不再报错
value: { // type: String, // default: '' },

@MarvinXu
Copy link

同上,只能先跳过eslint校验,这样不设置initialValue也不报错
image

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Accept You are right, we should do that bug outdated
Projects
None yet
Development

No branches or pull requests

5 participants