在浏览器环境下,我们如何使用JSX Transform
<script type="text/jsx">
/** @jsx React.DOM */
React.renderComponent(<h1>测试</h1>,document.getElementById('test'));
</script>
<script src="../build/react.js"></script>
<script src="../build/JSXTransformer.js"></script>
需要注意几点:
- script的type为text/jsx
- 注释 /** @jsx React.DOM */ 是必须的
renderCOmponent方法:
- 第一个参数:类似模板
- 第二个参数:dom
单独拿出:
- 新建一个文件test.js,type="text/jsx"
离线转化:
- npm install -g react-tools
- jsx --watch **/**/
本文部分内容:
http://facebook.github.io/react/docs/tooling-integration.html#productionizing-precompiled-jsx
http://facebook.github.io/react/docs/getting-started.html
JSXTransform在浏览器环境的应用
本文介绍如何在浏览器环境中使用JSXTransform处理JSX代码。通过设置script标签的type属性为text/jsx,并添加必要的注释声明,可以实现React组件的渲染。此外,还介绍了如何通过npm安装react-tools并配置监视任务来实现离线转换。

515

被折叠的 条评论
为什么被折叠?



