Reactjs 使用“在多个列中显示内容时出现问题”;“用户界面网格”;react-js中的语义ui类

Reactjs 使用“在多个列中显示内容时出现问题”;“用户界面网格”;react-js中的语义ui类,reactjs,semantic-ui,Reactjs,Semantic Ui,下面是使用语义ui类的组件 import React from 'react' class Gridview extends React.Component{ render(){ return( <div> <div class="ui grid"> <div class ="column"> <div class ="ui segment">

下面是使用语义ui类的组件

import React from 'react'

class Gridview extends React.Component{
   render(){
     return(
       <div>
         <div class="ui grid">
          <div class ="column">
           <div class ="ui segment">
             {this.props.data.id}<br/>
             {this.props.data.name}<br/>
             {this.props.data.price}<br/>
           </div>
          </div>
         </div>
      </div>
     )
   }
}

export default Gridview
从“React”导入React
类Gridview扩展了React.Component{
render(){
返回(
{this.props.data.id}
{this.props.data.name}
{this.props.data.price}
) } } 导出默认网格视图
下面是使用上述组件映射内容的组件。但在UI中显示时,它显示在一列中,而不是多列中:

import React, { Component } from 'react';
import Gridview from './Gridview'

class Product extends Component{
    constructor(){
      super();
      this.state = {  
         data:[
          {
           "id":1,
           "name":"Watch",
           "price":250
          },
          {
           "id":2,
           "name":"Wine",
           "price":252
          },
          {
           "id":3,
           "name":"Mobile",
           "price":289
          }
        ]
      }
    }
    render(){
       return(
        <div>
          {this.state.data.map((item) =>  <Gridview data ={item} />)}  
        </div>
       )
    }
}

export default Product
import React,{Component}来自'React';
从“./Gridview”导入Gridview
类产品扩展组件{
构造函数(){
超级();
this.state={
数据:[
{
“id”:1,
“姓名”:“手表”,
“价格”:250
},
{
“id”:2,
“名称”:“葡萄酒”,
“价格”:252
},
{
“id”:3,
“名称”:“手机”,
“价格”:289
}
]
}
}
render(){
返回(
{this.state.data.map((项)=>)}
)
}
}
导出默认产品

是。它将在一列中显示您的数据,因为您只添加了一列

<div class="ui grid">
    <div class="column">
        <div class="ui segment">
            {this.props.data.id}<br />
            {this.props.data.name}<br />
            {this.props.data.price}<br />
        </div>
    </div>
</div>

你可以在这里查阅

注意:在React中,我们使用
className
而不是
class


更新

对于要求

我有一个带有参数id、名称和价格的数据列表。我需要该列表跨越多个列,而不是单个参数

您需要更改父组件结构

<div className="ui grid">
    <div className="three column row">
        {this.state.data.map((item) =>  <Gridview data ={item} />)}
    </div>
</div>

是。它将在一列中显示您的数据,因为您只添加了一列

<div class="ui grid">
    <div class="column">
        <div class="ui segment">
            {this.props.data.id}<br />
            {this.props.data.name}<br />
            {this.props.data.price}<br />
        </div>
    </div>
</div>

你可以在这里查阅

注意:在React中,我们使用
className
而不是
class


更新

对于要求

我有一个带有参数id、名称和价格的数据列表。我需要该列表跨越多个列,而不是单个参数

您需要更改父组件结构

<div className="ui grid">
    <div className="three column row">
        {this.state.data.map((item) =>  <Gridview data ={item} />)}
    </div>
</div>

是否导入语义ui库?我已完成npm安装“语义ui”,并添加了“//cdn.jsdeliver.net/npm/semantic-ui@2.4.2/index.html中的dist/semantic.min.css“是否也导入语义ui库?我已完成npm安装“语义ui”,并添加了“//cdn.jsdeliver.net/npm/semantic”-ui@2.4.2/dist/semantic.min.css“在index.html中,谢谢您的回复。我有一个带有参数id、名称和价格的数据列表。我需要该列表跨越多个列,而不是单个参数。谢谢您的回复。我有一个带有参数id、名称和价格的数据列表。我需要该列表跨越多个列,而不是单个参数