React-使用中报错处理ERROR
React常见错误
①Uncaught SyntaxError: Inline Babel script: Adjacent JSX elements must be wrapped in an enclosing tag
虚拟DOM中只能有一个根标签②Warning: Invalid DOM property `class`. Did you mean `className`?
in div
在react的jsx语法中,class是一个类的关键词,所以标签的class属性要改为className③Uncaught SyntaxError: Inline Babel script: Unterminated JSX contents
在jsx中,所有的标签都要有闭合,比如input br img hr 要写成`<input /> <br />`④Warning: Invalid DOM property `for`. Did you mean `htmlFor`?
in label
in div
在react的jsx语法中,for是循环的关键词,所以标签的for属性要改为htmlFor
1.Warning: The tag <home> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.
在react中,组件名称要以大写字母开头
2.Warning: Failed prop type: You provided a
value
prop to a form field without anonChange
handler. This will render a read-only field. If the field should be mutable usedefaultValue
. Otherwise, set eitheronChange
orreadOnly
.表单元素设置value属性之后,默认就是只读属性,如果想要让它变成可以修改的控件需要设置onChange事件,让这个控件变成受控组件。
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634621.html