我是React.js和TypeScript的新手,我試圖獲得一個簡單的Hello World示例。我在我的Typings文件夾中添加了react-d.ts,react-dom.d.ts。當我在調試模式下運行站點時,我在打字稿文件的第一行得到「require is not defined」。我如何定義這個?Visual Studio 2015 TSX文件中的Hello World(React.js和TypeScript)
--------- index.html文件:--------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>TypeScript Test</title>
<!-- References. -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<h1>Before React Output</h1>
<div id="content"></div>
<script src="Test.js" type="text/javascript"></script>
</body>
</html>
----------- Test.tsx文件:-----------------
import React = require('react');
import ReactDOM = require('react-dom');
interface MyProps {
name: string;
}
class HelloWorld extends React.Component<MyProps, {}> {
constructor(props: MyProps) {
super(props);
}
render() {
return (<div> Hello {this.props.name} </div>);
}
}
ReactDOM.render(<HelloWorld name="World" />, document.getElementById('content'));