[英]React.Js not rendering in django project
我正在创建一个项目,其中反应不在 django localhost 上呈现任何内容
索引.html
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<div id="App">
<!---all will be define in App.js-->
<h1>Index.html </h1>
</div>
</body>
{% load static%}
<script src="{% static "frontend/main.js" %}"></script>
</html>
应用程序.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Header from './layout/header';
class App extends Component {
render() {
return (
<h1>App.JS</h1>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));
这是我的项目结构:
在运行 npm run dev 和 python manage.py runserver 之后,这是一切正常的状态,直到这里:
更改此源代码:
document.getElementById('app')
...到这个:
document.getElementById('App')
这是因为您的元素的 id 为“App”,但您正在尝试将 react app 挂接到元素“app”上。 它区分大小写。
document.getElementById 区分大小写
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.