Reactjs React js物料界面响应表

Reactjs React js物料界面响应表,reactjs,mobile,web-applications,responsive-design,material-ui,Reactjs,Mobile,Web Applications,Responsive Design,Material Ui,我正在react js中构建一个web应用程序,并使用material ui组件库。我正在使用table组件,它在桌面上看起来不错,但我希望它能够调整,在移动浏览器上也能看起来不错。物料界面支持这样的东西吗?我怎么做?当前情况的例子: PC\Mobile: 源代码: import React from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/style

我正在react js中构建一个web应用程序,并使用material ui组件库。我正在使用table组件,它在桌面上看起来不错,但我希望它能够调整,在移动浏览器上也能看起来不错。物料界面支持这样的东西吗?我怎么做?当前情况的例子: PC\Mobile:

源代码:

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';
import Paper from '@material-ui/core/Paper';

const styles = theme => ({
  root: {
    width: '100%',
    marginTop: theme.spacing.unit * 3,
    overflowX: 'auto',
  },
  table: {
    minWidth: 700,
  },
});

let id = 0;
function createData(name, calories, fat, carbs, protein) {
  id += 1;
  return { id, name, calories, fat, carbs, protein };
}

const data = [
  createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
  createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
  createData('Eclair', 262, 16.0, 24, 6.0),
  createData('Cupcake', 305, 3.7, 67, 4.3),
  createData('Gingerbread', 356, 16.0, 49, 3.9),
];

function SimpleTable(props) {
  const { classes } = props;

  return (
    <Paper className={classes.root}>
      <Table className={classes.table}>
        <TableHead>
          <TableRow>
            <TableCell>Dessert (100g serving)</TableCell>
            <TableCell numeric>Calories</TableCell>
            <TableCell numeric>Fat (g)</TableCell>
            <TableCell numeric>Carbs (g)</TableCell>
            <TableCell numeric>Protein (g)</TableCell>
          </TableRow>
        </TableHead>
        <TableBody>
          {data.map(n => {
            return (
              <TableRow key={n.id}>
                <TableCell component="th" scope="row">
                  {n.name}
                </TableCell>
                <TableCell numeric>{n.calories}</TableCell>
                <TableCell numeric>{n.fat}</TableCell>
                <TableCell numeric>{n.carbs}</TableCell>
                <TableCell numeric>{n.protein}</TableCell>
              </TableRow>
            );
          })}
        </TableBody>
      </Table>
    </Paper>
  );
}

SimpleTable.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SimpleTable);
从“React”导入React;
从“道具类型”导入道具类型;
从“@material ui/core/styles”导入{withStyles}”;
从“@material ui/core/Table”导入表格;
从“@material ui/core/TableBody”导入表体;
从“@material ui/core/TableCell”导入TableCell;
从“@material ui/core/TableHead”导入表头;
从“@material ui/core/TableRow”导入TableRow;
从“@material ui/core/Paper”导入纸张;
常量样式=主题=>({
根目录:{
宽度:“100%”,
marginTop:theme.space.unit*3,
溢出x:'自动',
},
表:{
最小宽度:700,
},
});
设id=0;
函数createData(名称、卡路里、脂肪、碳水化合物、蛋白质){
id+=1;
返回{id,name,carries,fat,carbs,protein};
}
常数数据=[
createData(“冷冻酸奶”,159,6.0,24,4.0),
createData(“冰淇淋三明治”,237,9.0,37,4.3),
createData('Eclair',262,16.0,24,6.0),
createData('Cupcake',305,3.7,67,4.3),
createData('Gingerbread',356,16.0,49,3.9),
];
函数SimpleTable(props){
常量{classes}=props;
返回(
甜点(100克)
卡路里
脂肪(g)
碳水化合物(克)
蛋白质(g)
{data.map(n=>{
返回(
{n.name}
{n.卡路里}
{n.fat}
{n.carbs}
{n.蛋白质}
);
})}
);
}
SimpleTable.propTypes={
类:PropTypes.object.isRequired,
};
导出默认样式(样式)(SimpleTable);

对于物料界面表格,应更改每个表格单元格的
右侧填充
左侧填充
, 你可以把代码放进去

从“React”导入React;
从“道具类型”导入道具类型;
从“@material ui/core/styles”导入{withStyles}”;
从“@material ui/core/Table”导入表格;
从“@material ui/core/TableBody”导入表体;
从“@material ui/core/TableCell”导入TableCell;
从“@material ui/core/TableHead”导入表头;
从“@material ui/core/TableRow”导入TableRow;
从“@material ui/core/Paper”导入纸张;
常量样式=主题=>({
根目录:{
显示:“flex”,
marginTop:theme.space.unit*3,
溢出x:'隐藏',
},
表:{
最小宽度:340,
},
表单元格:{
paddingRight:4,
填充左:5
}
});
设id=0;
函数createData(名称、卡路里、脂肪、碳水化合物、蛋白质){
id+=1;
返回{id,name,carries,fat,carbs,protein};
}
常数数据=[
createData(“冷冻酸奶”,159,6.0,24,4.0),
createData(“冰淇淋三明治”,237,9.0,37,4.3),
createData('Eclair',262,16.0,24,6.0),
createData('Cupcake',305,3.7,67,4.3),
createData('Gingerbread',356,16.0,49,3.9),
];
函数SimpleTable(props){
常量{classes}=props;
返回(
甜点(100克)
卡路里
脂肪(g)
碳水化合物(克)
蛋白质(g)
{data.map(n=>{
返回(
{n.name}
{n.卡路里}
{n.fat}
{n.carbs}
{n.蛋白质}
);
})}
);
}
SimpleTable.propTypes={
类:PropTypes.object.isRequired,
};
导出默认样式(样式)(SimpleTable);
要使其响应性,首先需要使用,例如,这是用于整页的网格系统:

 <Grid item xs={12}>
     <Table/>
  </Grid>


谢谢!附上我的源代码表componentanswer添加到我以前的one@El.Your“未捕获的SyntaxError:无法在模块外使用import语句”如果无法处理堆栈溢出代码段,请使用沙盒代码段
 <Grid item xs={12}>
     <Table/>
  </Grid>