首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >材料用户界面中的随机外部边界

材料用户界面中的随机外部边界
EN

Stack Overflow用户
提问于 2022-02-27 22:06:59
回答 2查看 277关注 0票数 0

我正在开发一个React应用程序,并且在我的大部分前端造型中使用了素材UI,我发现了一个奇怪的小bug,我似乎找不到它。在我的一些页面上,我在页面的边缘一直都有一个随机小白边,然后在另一些页面上使用边境线不见了。有什么办法能摆脱所有页面上的边框吗?

这是我的密码:

App.js

代码语言:javascript
复制
function App() {
    return (
        <div style={{backgroundColor: '#D3D3D3'}}>
            <Header />
            <h1>Gas App</h1>
            <Switch>
                <Route exact path="/register" component={Register} />
                <Route exact path="/login" component={Login} />
                <Route exact path="/logout" component={Logout} />

                <Route exact path="/cars" component={AllCars} />
                <Route exact path="/cars/register" component={CreateCar} />
                <Route exact path="/cars/edit/:id" component={EditCar} />
                <Route exact path="/cars/delete/:id" component={DeleteCar} />

                <Route exact path="/fillups" component={AllFillups} />
                <Route exact path="/fillups/new" component={CreateFillup} />
                <Route exact path="/fillups/edit/:id" component={EditFillup} />
                <Route exact path="/fillups/delete/:id" component={DeleteFillup} />

                <Route path="/:user" component={Profile} />
                

                <Route component={PageNotFound} />
            </Switch>
            <Footer />
        </div>

    )
}

Profile.js (具有随机白色边框)

代码语言:javascript
复制
export default function Profile() {

    const location = useLocation();
    console.log('Location=' + location.pathname.split("/")[2]);

    const { user } = useParams();
    let { path, url } = useRouteMatch();

    const [cars, setCars] = useState(null)
    const [fillups, setFillups] = useState(null)
    const { username } = useContext(Context);

    const locationToValue = (location) => {
        switch(location) {
            case 'stats':
                return 1;
            case 'fillups':
                return 2;
            case 'cars':
                return 3;
            default:
                return 0;
        }

    };

    const classes = useStyles();
    const [value, setValue] = useState(locationToValue(location.pathname.split("/")[2]));

    const handleChange = (event, newValue) => {
        setValue(newValue);
    };

    useEffect(() => {
        // Promise.all([
        //     axiosInstance.get('/fillups/?user__user_name=' + user),
        //     axiosInstance.get('/cars/?user__user_name=' + user)
        // ]).then(function ([res1, res2]) {
        //     setFillups(res1.data)
        //     setCars(res2.data);
        // });
        console.log('Value=' + value);
        console.log('Path=' + path);
        console.log('URL=' + url);
    }, [value]);

    return (
        <>
            <h1>{user}'s Profile</h1>
            <div className={classes.root}>
                <AppBar position="static">
                    <Tabs value={value} onChange={handleChange} aria-label="simple tabs example" variant="fullWidth">
                        <Tab label="Overview" component={Link} to={`${url}`} {...a11yProps(0)} />
                        <Tab label="Stats" component={Link} to={`${url}/stats`} {...a11yProps(1)} />
                        <Tab label="Fillups" component={Link} to={`${url}/fillups`} {...a11yProps(2)} />
                        <Tab label="Cars" component={Link} to={`${url}/cars`} {...a11yProps(3)} />
                    </Tabs>
                </AppBar>

                <Switch>
                    <Route exact path={`${path}`}>
                        <ProfileOverview user={user} />
                    </Route>

                    <Route exact path={`${path}/stats`}>
                        <ProfileStats user={user} />
                    </Route>

                    <Route exact path={`${path}/fillups`}>
                        <ProfileFillups user={user} />
                    </Route>

                    <Route exact path={`${path}/cars`}>
                        <ProfileCars user={user} />
                    </Route>
                </Switch>
            </div>
        </>
    )
}

和CreateCar.js (没有白色边框)

代码语言:javascript
复制
const useStyles = makeStyles((theme) => ({
    paper: {
        marginTop: theme.spacing(8),
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
    },
    form: {
        width: '100%', // Fix IE 11 issue.
        marginTop: theme.spacing(3),
    },
    submit: {
        margin: theme.spacing(3, 0, 2),
    },
}));

export default function CreateCar() {

    const classes = useStyles();

    return (
        <Container component="main" maxWidth="xs">
            <CssBaseline />
            <div className={classes.paper}>
                <Typography component="h1" variant="h5">
                    Register New Car
                </Typography>
                <form className={classes.form} noValidate>
                    <Grid container spacing={2}>
                        <Grid item xs={12}>
                            <TextField
                                variant="outlined"
                                required
                                fullWidth
                                id="car_name"
                                label="Car Name"
                                name="car_name"
                                autoComplete="car_name"
                                onChange={handleChange}
                            />
                        </Grid>
                        <Grid item xs={12}>
                            <TextField
                                variant="outlined"
                                required
                                fullWidth
                                id="make"
                                label="Make"
                                name="make"
                                autoComplete="make"
                                onChange={handleChange}
                            />
                        </Grid>
                        <Grid item xs={12}>
                            <TextField
                                variant="outlined"
                                required
                                fullWidth
                                id="model"
                                label="Model"
                                name="model"
                                autoComplete="model"
                                onChange={handleChange}
                            />
                        </Grid>
                        <Grid item xs={12}>
                            <FormControl fullWidth variant="outlined" className={classes.formControl}>
                                <InputLabel>Model Year</InputLabel>
                                <Select
                                    required
                                    onChange={handleSelectChange}
                                    id="model_year"
                                    label="Model Year"
                                    name="model_year"
                                    autoComplete="model_year"
                                    value={formData.model_year}
                                >
                                    {
                                    model_year_range.map((year) => (
                                        <MenuItem value={year}>{year}</MenuItem>
                                    ))
                                    }
                                </Select>
                            </FormControl>
                        </Grid>
                        <Grid item xs={12}>
                            <FormControl fullWidth variant="outlined" className={classes.formControl}>
                                <InputLabel>Status</InputLabel>
                                <Select
                                    required
                                    onChange={handleChange}
                                    id="status"
                                    label="status"
                                    name="status"
                                    autoComplete="status"
                                    value={formData.status}
                                >
                                    <MenuItem value="Active">Active</MenuItem>
                                    <MenuItem value="Inactive">Inactive</MenuItem>
                                </Select>
                            </FormControl>
                        </Grid>
                    </Grid>
                    <Button
                        type="submit"
                        fullWidth
                        variant="contained"
                        color="primary"
                        className={classes.submit}
                        onClick={handleSubmit}
                    >
                        Register Car
                    </Button>
                </form>
            </div>
        </Container>
    );
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-02-28 02:50:14

我解决了我的问题,同时削减我的代码,以一个更容易阅读的问题。在没有问题的组件中,我将整个组件包装在一个容器中,其中包括cssbaseline组件,而具有边框的组件则没有。因此,我的概要文件组件的返回语句现在如下:

代码语言:javascript
复制
return (
        <Container component="main">
            <CssBaseline />
            <h1>{user}'s Profile</h1>
            <div>
                {other component stuff here}
            </div>
        </Container>
    )
}
票数 1
EN

Stack Overflow用户

发布于 2022-05-25 14:04:51

我使用的是引导类container,因此我得到了填充。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71288825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档