【问题标题】:Why does ReactJS.net not have an import statement for React?为什么 ReactJS.net 没有 React 的导入语句?
【发布时间】:2018-04-01 15:29:39
【问题描述】:

我正在玩 https://reactjs.net/ ,并想在我现有的 ASP.NET MVC 应用程序中设置一个应用程序。

我使用 Visual Studio 中的“默认安装模板”制作了几个简单的 React 应用程序,但不是基于 ReactJS.net 并且内容只是一个子页面。

但是,如果我以教程模板为例:

var CommentBox = React.createClass({
    render: function () {
        return (
            <div className="commentBox">
                Hello, world! I am a CommentBox.
      </div>
        );
    }
});
ReactDOM.render(
    <CommentBox />,
    document.getElementById('content')
);

没有像 import * as React from 'react'; 这样的导入 React,我已经习惯了。

所以我的问题是:为什么不呢?什么时候应该导入 React?

【问题讨论】:

  • 它可能是在网站中抽象出来的。你绝对必须在你想在你的网络应用程序中使用它的任何文件中导入React

标签: asp.net asp.net-mvc reactjs reactjs.net


【解决方案1】:

因为在尝试导入 npm 包时需要 import React from 'react';。 Reactjs.Net 不使用 npm 依赖项,您需要使用 &lt;script src=""&gt; 将 CDN 放在您的视图中。基本上,当您使用 CDN 时,您会自动导入 React

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多