我想为此页面渲染一个背景图像,不是整个应用程序
这是我的登录页面代码,但我无法为此页面设置BG映像,我可以通过将其设置为应用程序组件,如果我对此进行相同的操作,则将其设置为整个应用程序我通过导入图像来完成的整个页面
import React, { useState } from "react";
import "./Loginp.css";
import axios from "axios";
import bgimg from "../../assets/Loginimage.jpg";
function Loginp() {
const [usernamed, setusername] = useState("");
const [passwordd, setpassword] = useState("");
const check = false;
function clicki() {
console.log("clicked");
const dat = {
username: usernamed,
password: passwordd,
};
axios.post("http://localhost:7000/login", dat).then((resp) => {
check = resp.data;
});
if (check) {
alert("User name already exists");
}
}
return (
<div
id="loginform"
style={{
backgroundImage: bgimg,
height: 100,
marginTop: 10,
textAlign: "center",
}}
>
<FormHeader title="Login" />
{/* <Form /> */}
<div>
<div class="row">
<label>Username</label>
<input
type="text"
placeholder="Enter your username"
onChange={(e) => {
setusername(e.target.value);
}}
/>
</div>
<div class="row">
<label>Password</label>
<input
type="text"
placeholder="Enter your password"
onChange={(e) => {
setpassword(e.target.value);
}}
/>
</div>
<div id="button" class="row">
<button onClick={clicki}>Log in</button>
</div>
</div>
</div>
);
}
const FormHeader = (props) => <h2 id="headerTitle">{props.title}</h2>;
export default Loginp;
this is my code for login page but i am not able to set bg image for this page i can do that by setting to app component which sets to whole application if i do the same to this then only the component is getting the background image not the whole page i am doing it by importing image
import React, { useState } from "react";
import "./Loginp.css";
import axios from "axios";
import bgimg from "../../assets/Loginimage.jpg";
function Loginp() {
const [usernamed, setusername] = useState("");
const [passwordd, setpassword] = useState("");
const check = false;
function clicki() {
console.log("clicked");
const dat = {
username: usernamed,
password: passwordd,
};
axios.post("http://localhost:7000/login", dat).then((resp) => {
check = resp.data;
});
if (check) {
alert("User name already exists");
}
}
return (
<div
id="loginform"
style={{
backgroundImage: bgimg,
height: 100,
marginTop: 10,
textAlign: "center",
}}
>
<FormHeader title="Login" />
{/* <Form /> */}
<div>
<div class="row">
<label>Username</label>
<input
type="text"
placeholder="Enter your username"
onChange={(e) => {
setusername(e.target.value);
}}
/>
</div>
<div class="row">
<label>Password</label>
<input
type="text"
placeholder="Enter your password"
onChange={(e) => {
setpassword(e.target.value);
}}
/>
</div>
<div id="button" class="row">
<button onClick={clicki}>Log in</button>
</div>
</div>
</div>
);
}
const FormHeader = (props) => <h2 id="headerTitle">{props.title}</h2>;
export default Loginp;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下。
try this.