<small id='iMRYJ'></small><noframes id='iMRYJ'>

  • <tfoot id='iMRYJ'></tfoot>
      <bdo id='iMRYJ'></bdo><ul id='iMRYJ'></ul>
  • <i id='iMRYJ'><tr id='iMRYJ'><dt id='iMRYJ'><q id='iMRYJ'><span id='iMRYJ'><b id='iMRYJ'><form id='iMRYJ'><ins id='iMRYJ'></ins><ul id='iMRYJ'></ul><sub id='iMRYJ'></sub></form><legend id='iMRYJ'></legend><bdo id='iMRYJ'><pre id='iMRYJ'><center id='iMRYJ'></center></pre></bdo></b><th id='iMRYJ'></th></span></q></dt></tr></i><div id='iMRYJ'><tfoot id='iMRYJ'></tfoot><dl id='iMRYJ'><fieldset id='iMRYJ'></fieldset></dl></div>

    <legend id='iMRYJ'><style id='iMRYJ'><dir id='iMRYJ'><q id='iMRYJ'></q></dir></style></legend>

        将 reactjs 与 requirejs 一起使用

        时间:2023-09-06
        • <tfoot id='ZdRhQ'></tfoot>
            <i id='ZdRhQ'><tr id='ZdRhQ'><dt id='ZdRhQ'><q id='ZdRhQ'><span id='ZdRhQ'><b id='ZdRhQ'><form id='ZdRhQ'><ins id='ZdRhQ'></ins><ul id='ZdRhQ'></ul><sub id='ZdRhQ'></sub></form><legend id='ZdRhQ'></legend><bdo id='ZdRhQ'><pre id='ZdRhQ'><center id='ZdRhQ'></center></pre></bdo></b><th id='ZdRhQ'></th></span></q></dt></tr></i><div id='ZdRhQ'><tfoot id='ZdRhQ'></tfoot><dl id='ZdRhQ'><fieldset id='ZdRhQ'></fieldset></dl></div>

            <small id='ZdRhQ'></small><noframes id='ZdRhQ'>

            • <bdo id='ZdRhQ'></bdo><ul id='ZdRhQ'></ul>
                  <tbody id='ZdRhQ'></tbody>

                  <legend id='ZdRhQ'><style id='ZdRhQ'><dir id='ZdRhQ'><q id='ZdRhQ'></q></dir></style></legend>

                  本文介绍了将 reactjs 与 requirejs 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  最近,我开始使用 reactjsbackbonejs 路由器来构建应用程序.

                  我通常使用 requirejs 进行依赖和代码管理.但是,当我尝试包含包含 jsx 语法的文件时出现问题.

                  这就是我目前所拥有的 router.js:

                  define(["backbone", "react"], function(Backbone, React) {var IndexComponent = React.createClass({渲染:函数(){返回 (

                  一些东西在这里</div>);}});返回 Backbone.Router.extend({路线:{: 指数"},索引:函数(){React.renderComponent(<IndexComponent/>, document.getElementById('index'));}});});

                  如何将 IndexComponent 放在它自己的文件中并在这个文件中调用它?我已经尝试过通常的方法(与我在主干和反应中使用的方法相同)但由于 jsx 语法而出现错误.

                  解决方案

                  所以我自己想通了.

                  我从这个 repo 获得了必要的文件和说明:jsx-requirejs-plugin.

                  一旦我有了 jsx 插件 和 的修改版本href="https://raw.github.com/alirussell/jsx-requirejs-plugin/master/js/JSXTransformer-0.10.0.js">JSXTransformer,我按照存储库中的说明更改了代码:

                  require.config({//...路径:{反应":路径/到/反应","JSXTransformer": "路径/到/JSXTransformer",jsx":路径/到/jsx 插件"...}//...});

                  然后,我可以通过 jsx! 插件语法来引用 JSX 文件.例如,要加载组件目录中的 Timer.jsx 文件:

                  require(['react', 'jsx!components/Timer'], function (React, Timer) {...React.renderComponent(, document.getElementById('timer'));...});

                  我还可以使用相同的代码访问具有 jsx 语法的 .js 文件:

                  require(['react', 'jsx!components/Timer'], function (React, Timer) {...React.renderComponent(, document.getElementById('timer'));...});

                  另外,我不需要使用 jsx 语法将 /** @jsx React.DOM */ 放在文件的顶部.

                  希望对你有帮助.

                  Recently, I started using reactjs along with a backbonejs router to build an application.

                  I usually use use requirejs for dependency and code management. But, problem arises when I try to include files that contain jsx syntax.

                  This is what I have so far as my router.js:

                  define(["backbone", "react"], function(Backbone, React) {
                  
                    var IndexComponent = React.createClass({
                      render : function() {
                        return (
                          <div>
                          Some Stuff goes here
                          </div>
                          );
                      }
                    });
                  
                  
                  
                    return Backbone.Router.extend({
                      routes : {
                        "": "index"
                      },
                      index : function() {
                        React.renderComponent(<IndexComponent />, document.getElementById('index'));
                      }
                    });
                  });
                  

                  How do I put IndexComponent in its own file and call it in this file ? I have tried the usual method (the same that I have used with backbone and react) but got an error due to jsx syntax.

                  解决方案

                  So I figured it out myself.

                  I got the necessary files and instructions from this repo: jsx-requirejs-plugin.

                  Once I had jsx plugin and modified version of JSXTransformer, I changed my code as instructed in the repository :

                  require.config({
                    // ...
                  
                    paths: {
                      "react": "path/to/react",
                      "JSXTransformer": "path/to/JSXTransformer",
                      "jsx": "path/to/jsx plugin"
                      ...
                    }
                  
                    // ...
                  });
                  

                  Then, I could reference JSX files via the jsx! plugin syntax. For example, to load the Timer.jsx file that is in a components directory:

                  require(['react', 'jsx!components/Timer'], function (React, Timer) {
                     ...
                     React.renderComponent(<Timer />, document.getElementById('timer'));
                     ...
                  });
                  

                  I could also access .js files that had jsx syntax in them using the same code:

                  require(['react', 'jsx!components/Timer'], function (React, Timer) {
                     ...
                     React.renderComponent(<Timer />, document.getElementById('timer'));
                     ...
                  });
                  

                  Also, I did not need to put /** @jsx React.DOM */ at the top of files using jsx syntax.

                  Hope it helps.

                  这篇关于将 reactjs 与 requirejs 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:H1-H6 标签最常见的字体大小是什么 下一篇:反应表中的导出到 CSV 按钮

                  相关文章

                1. <legend id='VPBZK'><style id='VPBZK'><dir id='VPBZK'><q id='VPBZK'></q></dir></style></legend>

                    <bdo id='VPBZK'></bdo><ul id='VPBZK'></ul>
                    <tfoot id='VPBZK'></tfoot>
                  1. <i id='VPBZK'><tr id='VPBZK'><dt id='VPBZK'><q id='VPBZK'><span id='VPBZK'><b id='VPBZK'><form id='VPBZK'><ins id='VPBZK'></ins><ul id='VPBZK'></ul><sub id='VPBZK'></sub></form><legend id='VPBZK'></legend><bdo id='VPBZK'><pre id='VPBZK'><center id='VPBZK'></center></pre></bdo></b><th id='VPBZK'></th></span></q></dt></tr></i><div id='VPBZK'><tfoot id='VPBZK'></tfoot><dl id='VPBZK'><fieldset id='VPBZK'></fieldset></dl></div>

                    <small id='VPBZK'></small><noframes id='VPBZK'>