Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

如何渲染用户输入的jsx模板到页面(react项目下)

问题:
怎么实现:react项目下,根据用户输入的jsx模板,结合数据,渲染结果到页面。
论证
我认为逻辑上是可行的,基本思路应该是:

  1. 拿到jsx
  2. 创建组件,组件的render函数return jsx代码
  3. 插入组件到页面节点

卡住了

**怎么用jsx字符串,创建组件的render函数?**



与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

先用Babel转换JSX语法,然后使用eval函数执行转化后的代码。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...