开发者社区> 问答> 正文

#React 如何使用React漂亮地打印JSON?

#React 如何使用React漂亮地打印JSON?

展开
收起
因为相信,所以看见。 2020-05-07 19:19:48 793 0
1 条回答
写回答
取消 提交回答
  • 阿里,我所有的向往

    我们可以使用

    标签,以便JSON.stringify()保留的格式:

    const data = { name: 'John', age: 42 }
    
    class User extends React.Component {
      render() {
        return (
          <pre>
            {JSON.stringify(data, null, 2)}
          </pre>
        )
      }
    }
    
    React.render(<User />, document.getElementById('container'))
    
    2020-05-07 19:20:20
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
利用编译将 Vue 组件转成 React 组件 立即下载
React Native 全量化实践 立即下载
React在大型后台管理项目中的工程实践 立即下载