当前位置:   article > 正文

react vue 背景挂载机器

react vue 背景挂载机器

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

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

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

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

子组件

  1. // positioning:{left:{direction:"center"},right:{direction:"cneter"}
  2. const BackgroundMounter = (props)=> {
  3. const BackgroundMounter = props.backGround
  4. let backGroundPost = ""
  5. let backGroundMessage = ""
  6. let backGroundSises = ""
  7. if(BackgroundMounter && BackgroundMounter.length > 0){
  8. BackgroundMounter.forEach((item,index) => {
  9. if(index +1 !== BackgroundMounter.length ){
  10. backGroundMessage += `url(${item.URL})` + "no-repeat " + ","
  11. backGroundSises += item?.style?.width + " " + item.style.height + ","
  12. backGroundPost += item.style.positioning.left.direction + " " + item.style.positioning.right.direction + ","
  13. }else {
  14. backGroundMessage += `url(${item.URL})` + "no-repeat "
  15. backGroundSises += item?.style?.width + " " + item.style.height
  16. backGroundPost += item.style.positioning.left.direction + " " + item.style.positioning.right.direction
  17. }
  18. });
  19. }
  20. return(<div style={{background:backGroundMessage,backgroundPosition:backGroundPost,backgroundSize:backGroundSises}}>
  21. {props.children}
  22. </div>)
  23. }
  24. export default BackgroundMounter

父组件

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

  1. /* eslint-disable no-unused-expressions */
  2. import React ,{ useEffect} from "react"
  3. import {useState} from "react"
  4. import { LockOutlined, UserOutlined } from '@ant-design/icons';
  5. import { Button, Checkbox, Form, Input } from 'antd';
  6. import logincss from './index.module.css'
  7. import Store from "../../Redux/redux";
  8. import { BrowserRouter, Route, Routes,Link,Outlet,useNavigate} from "react-router-dom"
  9. import UseClass from "./className";
  10. import BackgroundMounter from "./BackgroundMounter";
  11. const Log = () => {
  12. const usenavigate = useNavigate()
  13. const backGround = [
  14. {URL:"https://pic2.zhimg.com/v2-abee0fc1e685e6ecad60cd507a9cf6b5_b.jpg",style:{width:"100px",height:"100px",positioning:{left:{direction:"center"},right:{direction:"center"}}}
  15. },
  16. {URL:"https://pic2.zhimg.com/v2-abee0fc1e685e6ecad60cd507a9cf6b5_b.jpg",style:{width:"100px",height:"100px",positioning:{left:{direction:"center"},right:{direction:"bottom"}}}}
  17. ]
  18. // userstate 功能进行数据的绑定舰艇 两个参数 第一个为数据第二个为函数形式的变化只有通过函数进行改动才能更新页面的数据
  19. let [[form],setform] = useState(Form.useForm())
  20. const linitform = {
  21. password:'123456',
  22. username:'wangchangzhou'
  23. }
  24. const login = () => {
  25. console.log("deng录")
  26. // eslint-disable-next-line react-hooks/rules-of-hooks
  27. usenavigate('/home',{state:{login:true}})
  28. Store.dispatch({type:'login',login:true})
  29. }
  30. const valueSet = ()=> {
  31. const time = null
  32. if(time){
  33. clearTimeout(()=> {
  34. })
  35. }
  36. setTimeout(()=> {
  37. console.log("KKKKKKK")
  38. })
  39. }
  40. const getValue = ()=> {
  41. }
  42. useEffect(()=> {
  43. // console.log(useClass(logincss.login_bution,logincss.login_bution_BACK),"返回值")
  44. },[])
  45. const fundom = (value)=> {
  46. if(value ==="取消") {
  47. form.resetFields()
  48. }else {
  49. login()
  50. // console.log(form.getFieldsValue());
  51. // let value = form.getFieldsValue()
  52. // console.log(linitform === value)
  53. // // eslint-disable-next-line no-unused-expressions
  54. // if(linitform.password == form.getFieldsValue().password && linitform.password == form.getFieldsValue().password ){
  55. // login()
  56. // }
  57. }
  58. }
  59. return(
  60. <>
  61. {/* 背景挂载机 */}
  62. <BackgroundMounter backGround={backGround} >
  63. <div style={{height:"400px",width:"400px"}}>测试</div>
  64. </BackgroundMounter>
  65. {/* <button className={UseClass(logincss.login_bution,logincss.login_bution_BACK)} onClick={getValue()}>1</button>
  66. <button onClick={getValue()}>2jn kkkkkkkkk</button> */}
  67. </>)
  68. // return(
  69. // <div className={logincss.log_box}>
  70. // <Form
  71. // form={form}
  72. // className={logincss.log_box_from}
  73. // name="normal_login"
  74. // initialValues={{
  75. // }}
  76. // >
  77. // <div>
  78. // <span style={{fontSize:'20px',textShadow:'4px 4px 4px'}}>低代码测试</span>
  79. // <Form.Item
  80. // className={logincss.log_box_item}
  81. // name="username"
  82. // label ='名称'
  83. // rules={[
  84. // {
  85. // required: true,
  86. // message: 'Please input your Username!',
  87. // },
  88. // ]}
  89. // >
  90. // <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="请输入用户名" />
  91. // </Form.Item>
  92. // <Form.Item
  93. // className={logincss.log_box_item}
  94. // name="password"
  95. // label ='密码'
  96. // rules={[
  97. // {
  98. // required: true,
  99. // message: '请输入密码',
  100. // },
  101. // ]}
  102. // >
  103. // <Input
  104. // prefix={<LockOutlined className="site-form-item-icon" />}
  105. // type="password"
  106. // placeholder="请输入密码"
  107. // />
  108. // </Form.Item>
  109. // {/* <Form.Item className={logincss.log_box_item}>
  110. // <Form.Item name="remember" valuePropName="checked" noStyle>
  111. // <Checkbox>Remember me</Checkbox>
  112. // </Form.Item> */}
  113. // {/*
  114. // <a className="login-form-forgot" href="">
  115. // 记住密码
  116. // </a>
  117. // </Form.Item> */}
  118. // <Form.Item className={logincss.log_box_item}>
  119. // <Button onClick={()=>{ return fundom('登陆') }} type="primary" htmlType="submit" className="login-form-button">
  120. // 登录
  121. // </Button>
  122. // <Button onClick={()=>{ return fundom('取消') }} style={{marginLeft: '20px'}} type="primary" htmlType="submit" className="login-form-button">
  123. // 取消
  124. // </Button>
  125. // </Form.Item>
  126. // </div>
  127. // </Form>
  128. // <Outlet></Outlet>
  129. // </div>
  130. // )
  131. }
  132. export default Log

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/223877
推荐阅读
相关标签
  

闽ICP备14008679号