- 我正在尝试在 React 中显示一个文本框。
但我遇到了一个错误。 未捕获的语法错误:嵌入式:JSX 值应该是表达式或引用的 JSX 文本 (8:26)
你们能告诉我如何解决吗?
- 在下方提供。
https://jsfiddle.net/q7yvmsa3/3/
var Hello = React.createClass({
render: function() {
return (<div>Hello {this.props.name}
<textarea value = this.state.value>
there should be only 140 characters
</textarea>
</div>);
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
最佳答案
属性的值必须是表达式 {foo} 或引号文本“foo”
使用这条线
<textarea value = {this.state.value}>
代替
<textarea value = this.state.value>
例子:
var Hello = React.createClass({
getInitialState() {
return { value:"hello"};
},
render: function() {
return (<div>Hello {this.props.name}
<textarea value = {this.state.value}>
there should be only 140 characters
</textarea>
</div>);
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
工作 jsfiddle:https://jsfiddle.net/mwu28tx4/
关于javascript - 未捕获的语法错误 : embedded: JSX value should be either an expression or a quoted JSX text (8:26),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44213607/