html - 我想在 React JS 中添加背景图片全屏封面
问题描述
import React, {Component} from "react";
import CreateRoomPage from "./CreateRoomPage";
import RoomJoinPage from "./RoomJoinPage";
import Room from "./Room";
import { Grid, Button, ButtonGroup, Typography } from "@material-ui/core";
import {BrowserRouter as Router, Switch, Route, Link, Redirect} from "react-router-dom";
import Info from "./info";
我确实导入了图像路径和本地图像文件夹,但没有工作。
export default class HomePage extends Component {
constructor(props) {
super(props);
this.state = {
roomCode: null,
};
this.clearRoomCode = this.clearRoomCode.bind(this);
}
async componentDidMount(){
fetch("/api/user-in-room").then((response) => response.json()).then((data) => {
this.setState({
roomCode: data.code
});
});
}
renderHomePage(){
return(
<Grid container spacing={3}>
<Grid item xs={12} align="center">
<Typography variant = "h3" compact="h3">
Xone Music
</Typography>
</Grid>
<Grid item xs={12} align="center">
<ButtonGroup disableElevation variant="contained" color="primary">
<Button color="primary" to="/join" component={Link}>
Join a Room
</Button>
<Button color="default" to="/info" component = {Link} >
<Typography variant = "h5" compact="h5">
?
</Typography>
</Button>
<Button color="secondary" to="/create" component = {Link}>
Create a Room
</Button>
</ButtonGroup>
</Grid>
</Grid>
);
}
clearRoomCode(){
this.setState({
roomCode:null
});
}
render(){
return (
<Router>
<Switch>
<Route exact path="/" render={() => {
return this.state.roomCode ? (<Redirect to={`/room/${this.state.roomCode}`}/>) : (this.renderHomePage());
}}/>
<Route path="/join" component={RoomJoinPage}/>
<Route path="/info" component={Info}/>
<Route path="/create" component={CreateRoomPage}/>
<Route path="/room/:roomCode" render={(props) => {
return <Room {...props} leaveRoomCallback= {this.clearRoomCode} />
}}/>
</Switch>
</Router>);
}
}
我想添加 bg 图像,但我不知道如何或在哪里放置它。
这个页面是我的登陆页面。
当我导入本地图像文件夹时,我收到了一些关于 webpack 的错误。
解决方案
推荐阅读
- javascript - 满足条件后如何防止 IF 语句运行
- gulp - 如何使用 gulp ngrok-serve 生成包?
- java - Lucene如何在搭配上马马虎虎
- python - `app.route` 和 `template_render` 在 Flask 中不起作用
- javascript - 当我使用不记名令牌发送请求时,服务器返回状态 403 禁止
- java - 为什么 mean 方法不能正常工作?
- c# - ConfigurationManager.AppSettings 不返回任何内容
- java - 使用fabric8 api进行连接测试
- php - 有没有办法根据 laravel 中相同模型中的值获得不同的值以及行数?
- c# - Asp.net Core3.1 SignalR Hub消耗大量内存,出现Out of Memory异常并终止WebSocket连接