![](/img/trans.png)
[英]How Can I Place RequireJS Config in Separate File and Make the r.js Optimizer Work?
[英]How to get react components in a separate static js file read by Django? What is the least to be installed to make it work?
需要做哪些修改? 和/或為此工作最少需要安裝什么?
首先,在 static reactclasses.js 文件中,該文件僅包含此文件。 (還有什么需要補充的嗎?)
class Login extends React.Component {
render() {
return (
<div id="login">
<form action="/login" method="POST">
<input type="text" name="username" placeholder="Username" required/>
<input type="password" name="password" placeholder="Password" required/>
<input type="submit" value="Submit"/>
</form>
</div>
);
}
}
在 html 文件中
<!--- in the head tag --->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script src="{% static 'reactclasses.js' %}" type="text/babel"></script>
<!--- in a script tag with type=text/babel in the body tag -->
ReactDOM.render(<login />, document.querySelector("thediv"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.