jsx-to-json
v0.2.3
Published
将 jsx 转化为 json格式的组件树
Downloads
22
Readme
jsx-to-json
将 JSX 代码转化为 JSON 对象, 例如
<Layout>
<Row style={{ padding: 10, backgroundColor: "#EFEFEF" }}>
<BroccoliVote
style={{ fontSize: "80%" }}
options= {[
{ name: "选项1", value: 1 },
{ name: "选项2", value: 2 },
{ name: "选项3", value: 3 },
]}
/>
</Row>
<Row>
<Share text="一起来参与投票吧!亮出你的态度"/>
</Row>
</Layout>
转化为
{
"type": "Layout",
"children": [
{
"type": "Row",
"props": {
"style": {
"padding": 10,
"backgroundColor": "#FFF"
}
},
"children": [
{
"type": "h1",
"text": "标题"
},
{
"type": "BroccoliVote",
"props": {
"style": {
"fontSize": "80%"
},
"options": [
{
"name": "选项1",
"value": 1
},
{
"name": "选项2",
"value": 2
},
{
"name": "选项3",
"value": 3
}
]
}
}
]
},
{
"type": "Row",
"children": [
{
"type": "Share",
"props": {
"text": "一起来参与投票吧!亮出你的态度"
}
}
]
}
]
}
使用
import { jsxToJson } from 'jsx-to-json';
const jsonObject = jsxToJson(code);