React无法在MVC项目中渲染简单的Hello World [英] React is failing to render simple Hello World in MVC project
本文介绍了React无法在MVC项目中渲染简单的Hello World的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始了ASP.NET MVC项目,并添加了以下资源:
I got starting ASP.NET MVC project with the following resources added:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
<script src="~/Scripts/require.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.24.0/babel.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
@RenderSection("scripts", required: false)
Index.cshtml中的部分脚本:
Section scripts in Index.cshtml:
<div id="root"></div>
@section scripts
{
<script src="~/Scripts/ReactJS/Index.js" type="text/babel"></script>
}
文件本身:
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
结果是空白页,没有错误.我不想使用Node.js,甚至都不想使用require.js和babel.js,但似乎我必须这样做.Reactjs正常工作的最小依赖是什么?
The result is empty page with no errors. I do not want to use Node.js, I do not want to use even require.js and babel.js, but it seems I have to. What are the minimal dependencies of reactjs to work properly?
推荐答案
请在h1之前使用div
var Root = React.createClass({
render: function () {
return (<div>
<h1>Hello, world!</h1> </div>);
}
});
这篇关于React无法在MVC项目中渲染简单的Hello World的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文