question
Sometimes we encounter the problem of multiple background images being displayed in one place during the project.
At that time, the project was in a hurry and had no time to make tool functions. After being optimized by the team, it was time to write tool functions.
technology
Slots, and css backgrounds This is not the final state. There are two properties for background positioning.
This is implemented in react. vue is OK.
Subcomponents
// positioning:{left:{direction:"center"},right:{direction:"cneter"} const BackgroundMounter = (props)=> { const BackgroundMounter = let backGroundPost = "" let backGroundMessage = "" let backGroundSises = "" if(BackgroundMounter && > 0){ ((item,index) => { if(index +1 !== ){ backGroundMessage += `url(${})` + "no-repeat " + "," backGroundSises += item?.style?.width + " " + + "," backGroundPost += + " " + + "," }else { backGroundMessage += `url(${})` + "no-repeat " backGroundSises += item?.style?.width + " " + backGroundPost += + " " + } }); } return(<div style={{background:backGroundMessage,backgroundPosition:backGroundPost,backgroundSize:backGroundSises}}> {} </div>) } export default BackgroundMounter
Parent component
backGround Note: The width of the block-level element will be defined according to the width of the parent component, so it should be converted to the in-line element to prevent the inheritance of width, but do not convert the in-line element into the block-level element w3c regulations
/* eslint-disable no-unused-expressions */ import React ,{ useEffect} from "react" import {useState} from "react" import { LockOutlined, UserOutlined } from '@ant-design/icons'; import { Button, Checkbox, Form, Input } from 'antd'; import logincss from './' import Store from "../../Redux/redux"; import { BrowserRouter, Route, Routes,Link,Outlet,useNavigate} from "react-router-dom" import UseClass from "./className"; import BackgroundMounter from "./BackgroundMounter"; const Log = () => { const usenavigate = useNavigate() const backGround = [ {URL:"/v2-abee0fc1e685e6ecad60cd507a9cf6b5_b.jpg",style:{width:"100px",height:"100px",positioning:{left:{direction:"center"},right:{direction:"center"}}} }, {URL:"/v2-abee0fc1e685e6ecad60cd507a9cf6b5_b.jpg",style:{width:"100px",height:"100px",positioning:{left:{direction:"center"},right:{direction:"bottom"}}}} ] // Userstate function to bind data to ship. Two parameters: the first is data and the second is a change in function form. Only by changing the function can the page data be updated. let [[form],setform] = useState(()) const linitform = { password:'123456', username:'wangchangzhou' } const login = () => { ("deng record") // eslint-disable-next-line react-hooks/rules-of-hooks usenavigate('/home',{state:{login:true}}) ({type:'login',login:true}) } const valueSet = ()=> { const time = null if(time){ clearTimeout(()=> { }) } setTimeout(()=> { ("KKKKKKK") }) } const getValue = ()=> { } useEffect(()=> { // (useClass(logincss.login_bout,logincss.login_bout_BACK),"Return value") },[]) const fundom = (value)=> { if(value ==="Cancel") { () }else { login() // (()); // let value = () // (linitform === value) // // eslint-disable-next-line no-unused-expressions // if( == ().password && == ().password ){ // login() // } } } return( <> {/* Background mounter */} <BackgroundMounter backGround={backGround} > <div style={{height:"400px",width:"400px"}}>test</div> </BackgroundMounter> {/* <button className={UseClass(logincss.login_bution,logincss.login_bution_BACK)} onClick={getValue()}>1</button> <button onClick={getValue()}>2jn kkkkkkkkk</button> */} </>) // return( // <div className={logincss.log_box}> // <Form // form={form} // className={logincss.log_box_from} // name="normal_login" // initialValues={{ // }} // > // <div> // <span style={{fontSize:'20px',textShadow:'4px 4px 4px'}}>Low code test</span>// < // className={logincss.log_box_item} // name="username" // label = 'name'// rules={[ // { // required: true, // message: 'Please input your Username!', // }, // ]} // > // <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Please enter username" />// </> // < // className={logincss.log_box_item} // name="password" // label = 'password'// rules={[ // { // required: true, // message: 'Please enter your password',// }, // ]} // > // <Input // prefix={<LockOutlined className="site-form-item-icon" />} // type="password" // placeholder="Please enter your password"// /> // </> // {/* < className={logincss.log_box_item}> // < name="remember" valuePropName="checked" noStyle> // <Checkbox>Remember me</Checkbox> // </> */} // {/* // <a className="login-form-forgot" href=""> // Remember the password // </a> // </ */} // < className={logincss.log_box_item}> // <Button onClick={()=>{ return fund('Login') }} type="primary" htmlType="submit" className="login-form-button">// Log in// </Button> // <Button onClick={()=>{ return fund('Cancel') }} style={{marginLeft: '20px'}} type="primary" htmlType="submit" className="login-form-button">// Cancel// </Button> // </> // </div> // </Form> // <Outlet></Outlet> // </div> // ) } export default Log
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.