Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 JSX 中插入一些代码;
使用价值道具:
孩子:
<Child value=" var s = 'hello'; console.log(s); " />
家长:
<div dangerouslySetInnerHTML={this.props.value}>
但是没有换行;
使用儿童:
<Child> var s = 'hello'; console.log(s); <Child/>
结果:编译错误
如何解决这个问题呢?
您可以使用反引号括起来的模板字符串文字:
<Child value={` var s = 'hello'; console.log(s); `} />
参考: