jtj

jsx-to-json

将 jsx 转化为 json格式的组件树

Showing:

Popularity

Downloads/wk

123

Maintenance

No Maintenance Data Available

Package

Dependencies

7

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

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);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial