簡體   English   中英

反應組件未在 django 索引 html 模板中呈現

[英]React component not rendering in django index html template

索引 html:

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Babon</title>
</head>
<body>
  <div id="App">
      <!-- React will load here -->
  </div>
</body>
{% load static %}
<script src="{% static 'frontend/main.js' %}"></script>
</html>

索引.tsx:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
  <App />,
  document.getElementById('App'),
);

當我運行我的服務器時,我可以看到 div 正在呈現“React 將在此處加載”消息,但我的組件似乎沒有呈現。

有任何想法嗎?

在控制台中出現此錯誤:

index.tsx:4 Uncaught Error: Cannot find module './App'
    at webpackMissingModule (index.tsx:4)
    at eval (index.tsx:4)
    at Object../src/index.tsx (main.js:19)
    at __webpack_require__ (main.js:133)
    at main.js:156
    at main.js:158

也許這是我的 tsx 文件被正確編譯的問題?

您應該在 index.tsx 的同一目錄中有一個名為 App.tsx 的文件,這樣您就可以在索引文件的頂部配置調用。

import App from './App';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM