reactjs - 无法在 react.js 应用程序中使用 react-bootstrap 在渲染部分使用带有 Row 和 Col 的映射函数
问题描述
我正在使用react-bootstrap和reactjs。我使用以下命令安装了 react-bootstrap:
npm install react-bootstrap
代替
npm install react-bootstrap bootstrap
因为我想将 CDN 用于样式表。
现在我想products_all
从状态显示以 Row-Column 样式呈现,以便每个Row
包含 4 Cols
。该products_all
状态充满了一个 ajax 调用,axios
为了保持代码简洁,我没有在这里展示。
import React, { Component } from 'react'
import Col from 'react-bootstrap/Col'
import Row from 'react-bootstrap/Row'
class ProductsWise extends Component {
constructor (props) {
super(props)
this.state = {
products_all:[],
}
render () {
const cols = this.state.products_all.map( (item, idx) => (
<Col key={item} lg={3}>
....
<Col>
));
const noRows = Math.ceil(this.state.products_all.length / 4);
const rows = Array.from(Array(noRows)).map((n, i) =>(
<Row>
{cols.slice(i* 4, i * 4)}
</Row>
));
return rows;
}
}
export default ProductsWise
但是npm run watch
在命令提示符下使用命令我得到错误:
未终止的JSX 内容,它表示在</Row>
.
那么如何摆脱错误呢?
解决方案
我认为你需要在/
你的第二个中添加一个Col
来关闭它,即</Col>
推荐阅读
- java - 如何解决Android studio 3.1.3 启动错误
- javascript - 如何分别制作 DBconnection 和 Node.js 查询文件
- ubuntu - 使用 VSTS 将 .net 核心应用程序部署到 Ubuntu
- python - Mac 安装后未找到 LightGBM 图像
- c# - 仅使用 .NET 在 Google App Engine Flex 中接收 HTTP 请求。如何只允许HTTPS?
- java - 将项目添加到在 FXML 中创建的 ComboBox(在 JavaFX 应用程序的 Controller 类中)
- c# - 是否可以将文本和 unicode 字符添加到 cosmos gui?
- python - Python内存别名(简单)
- nginx - Kubernetes 的 Nginx 入口“连接被拒绝”
- python - 将 csv 文件从 VM 上传到 bigquery 的有效方法是什么