react vue 背景挂载机器

问题:项目当中我们有的时候会遇到多个背景图片在一个地方展示的问题

当时项目比较急没有时间做工具函数,被团队优化以后有,时间进行工具函数编写

技术: 插槽 , 和 css 背景 这个还不是最终的状态 背景定位还有两个属性

这个是react 方式实现的 vue 也可以的

子组件

复制代码
// positioning:{left:{direction:"center"},right:{direction:"cneter"}
const BackgroundMounter = (props)=> {
       const BackgroundMounter = props.backGround
       let backGroundPost = ""
       let backGroundMessage = ""
       let backGroundSises = ""
      
       if(BackgroundMounter && BackgroundMounter.length > 0){
              BackgroundMounter.forEach((item,index) => {
                 if(index +1 !== BackgroundMounter.length  ){
                     backGroundMessage += `url(${item.URL})` + "no-repeat "  + ","
                     backGroundSises += item?.style?.width + " " + item.style.height + ","
                     backGroundPost +=  item.style.positioning.left.direction + " " +  item.style.positioning.right.direction + ","
                 }else {
                     backGroundMessage += `url(${item.URL})` + "no-repeat " 
                     backGroundSises += item?.style?.width + " " + item.style.height 
                     backGroundPost +=  item.style.positioning.left.direction + " " +  item.style.positioning.right.direction 
                 }
              });
       }  
      
       return(<div style={{background:backGroundMessage,backgroundPosition:backGroundPost,backgroundSize:backGroundSises}}>
              {props.children}
            
       </div>)
}
export default BackgroundMounter

父组件

backGround 注意点 块级元素宽度宽度会随着父组件的宽度进行定义,所以要转为 行内元素阻止宽度继承,但是一定不要把行内元素转化为块级元素 w3c 规定

复制代码
/* 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 './index.module.css'
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:"https://pic2.zhimg.com/v2-abee0fc1e685e6ecad60cd507a9cf6b5_b.jpg",style:{width:"100px",height:"100px",positioning:{left:{direction:"center"},right:{direction:"center"}}}
      },
      {URL:"https://pic2.zhimg.com/v2-abee0fc1e685e6ecad60cd507a9cf6b5_b.jpg",style:{width:"100px",height:"100px",positioning:{left:{direction:"center"},right:{direction:"bottom"}}}}

]

     //  userstate 功能进行数据的绑定舰艇 两个参数 第一个为数据第二个为函数形式的变化只有通过函数进行改动才能更新页面的数据
     let    [[form],setform] =  useState(Form.useForm())   
     const linitform =  {
         password:'123456',
         username:'wangchangzhou'
     }
     const login = () => {
      console.log("deng录")
      // eslint-disable-next-line react-hooks/rules-of-hooks
      usenavigate('/home',{state:{login:true}}) 
      Store.dispatch({type:'login',login:true})
     }
     const valueSet = ()=> {
      const time = null
      if(time){
               clearTimeout(()=> {
                
               })
      }
       
       setTimeout(()=> {
         console.log("KKKKKKK")
       })
     }
     const getValue = ()=> {
          
     }
     useEffect(()=> {
      //  console.log(useClass(logincss.login_bution,logincss.login_bution_BACK),"返回值")
     },[])
        const fundom = (value)=> {
         if(value ==="取消") {
          form.resetFields()
         }else {
          login()
          //   console.log(form.getFieldsValue());
          //  let value = form.getFieldsValue()
          //   console.log(linitform === value)
          //   // eslint-disable-next-line no-unused-expressions
          //      if(linitform.password == form.getFieldsValue().password && linitform.password == form.getFieldsValue().password ){
          //       login()
          //      }
            
         }
       }
       return(
       <>   
            {/* 背景挂载机 */}
            <BackgroundMounter backGround={backGround} >
               <div style={{height:"400px",width:"400px"}}>测试</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'}}>低代码测试</span>
//       <Form.Item
//       className={logincss.log_box_item}
//         name="username"
//         label ='名称'
//         rules={[
//           {
//             required: true,
//             message: 'Please input your Username!',
//           },
//         ]}
//       >
//         <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="请输入用户名" />
//       </Form.Item>
//       <Form.Item
//        className={logincss.log_box_item}
//         name="password"
//         label ='密码'
//         rules={[
//           {
//             required: true,
//             message: '请输入密码',
//           },
//         ]}
//       >
//         <Input
//           prefix={<LockOutlined className="site-form-item-icon" />}
//           type="password"
//           placeholder="请输入密码"
//         />
//       </Form.Item>
//       {/* <Form.Item  className={logincss.log_box_item}>
//         <Form.Item name="remember" valuePropName="checked" noStyle>
//           <Checkbox>Remember me</Checkbox>
//         </Form.Item> */}
// {/* 
//         <a className="login-form-forgot" href="">
//            记住密码
//         </a>
//       </Form.Item> */}

//       <Form.Item  className={logincss.log_box_item}>
//         <Button onClick={()=>{ return fundom('登陆') }} type="primary" htmlType="submit" className="login-form-button">
//           登录
//         </Button>
//         <Button onClick={()=>{ return fundom('取消') }} style={{marginLeft: '20px'}} type="primary" htmlType="submit" className="login-form-button">
//           取消
//         </Button>
//       </Form.Item>
//       </div>
//     </Form>
//     <Outlet></Outlet>
//         </div>
//        )
}
export default Log
相关推荐
pan_junbiao2 分钟前
Whistle 抓包工具的安装与使用
前端·测试工具·压力测试·抓包
Cory.眼8 分钟前
前端调用后端接口全流程实战
前端·调用接口
云水一下10 分钟前
TypeScript 从零基础到精通(四):面向对象编程(类与继承)
javascript·typescript
牛栓柱15 分钟前
【后端实战】用 Supabase + React/TS 零成本构建高并发 Multi-Agent 服务
前端·数据库·人工智能·后端·react.js·前端框架
木斯佳18 分钟前
前端八股文面经大全:百度-Agent部门-前端一面(2026-06-04)·面经深度解析
前端
shmily麻瓜小菜鸡18 分钟前
Bootstrap 4 常用工具类速查表
前端·javascript·bootstrap
CDN36020 分钟前
【架构进阶】告别配置漂移!用 NodeNext + Workspace 打造优雅的 TypeScript Monorepo
前端·javascript·typescript
协享科技26 分钟前
前端 SSE 流式响应处理实践:从接收、解析到渲染
前端·人工智能·程序人生·go·ai编程·sse
超人不会飞_Jay33 分钟前
6.2前端笔记
前端·javascript·笔记
鹏大师运维34 分钟前
统信UOS安装Subtitle Edit并使用Edge-TTS生成AI语音教程
linux·前端·人工智能·edge·麒麟·统信uos·ai语音