Reactjs:输入字段有值但显示为空

时间:2018-01-22 17:54:01

标签: html reactjs input

面对一个奇怪的问题。我的反应应用程序中有一个输入字段。 我使用defaultValue道具设置输入字段的值。 但是我的输入字段没有填充。它显示为("")。但我可以在dom中看到其value属性中的值。 enter image description here

以下是该输入的反应道具

enter image description here

知道我在这里缺少什么吗?

1 个答案:

答案 0 :(得分:1)

您只能在不受控制的组件上使用defaultValue,但您的输入有onChange道具,这使得它受到控制。您应该通过value prop。

设置默认值

https://reactjs.org/docs/uncontrolled-components.html - 这里有一些关于它的信息。