javascript - 没有输出 React Js for web
问题描述
我的反应应用程序没有输出,没有错误。首先它工作正常,现在同样的事情不起作用。
我尝试过 React.render 和 ReactDOM.render 我尝试过使用和不使用 render()
应用程序.js
import ReactDOM from 'react-dom';
import './index.css';
function Greeting()
{
return
(
<h1>helllo</h1>
);
}
ReactDOM.render
(
<Greeting/>,document.getElementById('root')
);
--------------------------**Index.css**----------------------------------
```body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
解决方案
问题在于return
statement( line-break issue
),如果您在 中返回值next line
,它将被视为undefined
。这就是为什么你在 dom 上看不到任何东西的原因。阅读这些答案以获得更多理解
return
(
<h1>helllo</h1>
);
改成
return (
<h1>helllo</h1>
);
还要稍微格式化你的代码。
ReactDOM.render(
<Greeting/>,document.getElementById('root')
);
推荐阅读
- machine-learning - 特征工程:我们称之为从数据集中生成特征值的过程?
- postgresql - 如何避免在 postgres 中顺序删除和插入的竞争条件
- python - Flask 没有显示我的全部列表
- javascript - 如何使引导轮播交互?
- python - 如何在不了解输入和输出数组的情况下将对象检测模型(在其冻结图中)转换为 .tflite
- r - 如何使图例元素沿数据框行排序但不重新排序?
- c++ - gmock 可以模拟未定义的方法吗?
- mysql - WooCommerce 产品属性键和值存储在哪里
- python - 如何用 2D Numpy 数组替换弹出/附加?
- java - 使用java从具有唯一标识符的字符串中获取子字符串