reactjs - ReactJS 响应式布局对第一个网格无响应
问题描述
我正在为 App.js 使用以下代码
import React, {Component} from "react"
import TextField from '@material-ui/core/TextField';
import Grid from '@material-ui/core/Grid';
const styles = theme => ({
root: {
flexGrow: 1,
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
},
});
class App extends Component {
render() {
return (
<main>
<div class="root">
<Grid container spacing={2}>
<Grid item xs={6}>
<TextField
id="filled-name"
label="First Name"
margin="normal"
variant="filled"
/>
</Grid>
<Grid item xs={2}>
<TextField
id="filled-name"
label="Last Name"
margin="normal"
variant="filled"
/>
</Grid>
</Grid>
</div>
</main>
)
}
}
export default App
但是在检查元素响应设置期间,名字框没有响应,如果我选择不同的移动屏幕选项,布局并不总是如预期的那样。
有人可以发表意见吗?
解决方案
您应该正确遵循文档
1)您使用的是类而不是类名。
2)您没有使用样式对象,也没有使用带有样式的高阶组件。
Demo.js
供参考的文件:- 和工作代码沙箱链接
import React, { Component } from "react";
import TextField from "@material-ui/core/TextField";
import Grid from "@material-ui/core/Grid";
import { withStyles } from "@material-ui/core/styles";
const styles = theme => ({
root: {
flexGrow: 1
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
width: 100
}
});
class Demo extends Component {
render() {
const { classes } = this.props;
return (
<main>
<div className={classes.root}>
<Grid container spacing={24}>
<Grid item xs={12} sm={6}>
<TextField
id="filled-name"
label="First Name"
margin="normal"
variant="filled"
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
id="filled-name"
label="Last Name"
margin="normal"
variant="filled"
/>
</Grid>
</Grid>
</div>
</main>
);
}
}
export default withStyles(styles)(Demo);
希望有帮助!!!
推荐阅读
- c++ - 尽管存在 Windows 或 MinGW 错误,但可以体面地显示标准输出的大型 UTF-8 编码字符串
- python - 在 Python 中使用 OpenCV 检测手掌线
- java - 具有大型资源文件的 Android APK
- javascript - 更改下拉菜单上的猫鼬查询
- android - 尝试使用 cordova 构建 APK 时出错 | :app:mergeReleaseResources 失败
- r - Mlogit 错误:solve.default(H, g[!fixed]) 中的错误:Lapack 例程 dgesv:系统完全是奇异的:U[6,6] = 0
- c# - 在 C# 中,在一个块中对对象执行操作并返回它所需的最少代码构造?标识符的长度不重要
- python - 使用 bash 粘合 python 和 c++
- regex - 有没有办法让我缩小正则表达式查询?
- linux - 广播数据包不通过 Linux veth 隧道传播