当前位置:   article > 正文

vue3+element plus组件库中el-carousel组件走马灯特效,当图片变动时下面数字也随着图片动态变化_el-carousel 动态

el-carousel 动态

1.效果图

2.html

  1. <section style="height:30%">
  2. <div class="left-img1-title">
  3. <img src="../assets/img/title.png"
  4. alt=""
  5. srcset="">
  6. <div class="text">回收垃圾数量</div>
  7. </div>
  8. <div style="">
  9. <el-carousel :interval="4000"
  10. indicator-position="none"
  11. type="card"
  12. height="100px"
  13. @change="swch">
  14. <el-carousel-item v-for="item in carouselImg"
  15. :key="item">
  16. <h3 text="2xl"
  17. justify="center"><img :src="item.img"
  18. alt=""
  19. srcset=""
  20. class="carousel-image"
  21. style="height: 100px;"
  22. justify="center"></h3>
  23. </el-carousel-item>
  24. </el-carousel>
  25. </div>
  26. <div class="carousel-text">
  27. <div v-for="(item,index) in count"
  28. :key="index">
  29. <div>{{item.name}}</div>
  30. <div class="text">{{item.data}}kg</div>
  31. </div>
  32. </div>
  33. </section>

3.js 

  1. // 准备数据
  2. // 1.vue3采用import的方式引入图片,不然会报错,引入方法之一
  3. import bl from '@/assets/img/bl.png'
  4. import js from '@/assets/img/js.png'
  5. import sl from '@/assets/img/sl.png'
  6. import zl from '@/assets/img/zl.png'
  7. import zw from '@/assets/img/zw.png'
  8. import pie from '@/components/pie.vue'
  9. //2.本页面采用第二种方式,结合html代码
  10. // 引入本地图片
  11. let carouselImg = reactive([
  12. {img: bl},
  13. {img: js},
  14. {img: sl},
  15. {img: zl},
  16. {img: zw},
  17. ])
  18. //回收列表
  19. let countList = reactive([])
  20. //回收垃圾数量
  21. let count = reactive([
  22. { name: '今日回收数量', data: 0 },
  23. { name: '累计回收总数', data: 0 },
  24. { name: '户均回收量' , data: 0 }
  25. ])
  26. // 填充回收量
  27. const getNum = (data) => {
  28. let list = [1,2,3,4,5]
  29. let allCount = 0
  30. let allDay = 0
  31. data.map(item=> {
  32. allCount += (item.weight*100)
  33. allDay += (item.weightDay*100)
  34. item.typeId=="1026"?list[0]=item:''
  35. item.typeId=="4"?list[1]=item:''
  36. item.typeId=="2"?list[2]=item:''
  37. item.typeId=="1017"?list[3]=item:''
  38. item.typeId=="1121"?list[4]=item:''
  39. })
  40. allCount = (allCount/100).toFixed(2)
  41. allDay = (allDay/100).toFixed(2)
  42. countList = list
  43. // 回收量初始化
  44. count[0].data = list[0].weightDay
  45. count[1].data = list[0].weight
  46. count[2].data = list[0].households
  47. }
  48. // 幻灯片切换(回收量切换)
  49. const swch = (index) => {
  50. let list = countList
  51. count[0].data = list[index].weightDay
  52. count[1].data = list[index].weight
  53. count[2].data = list[index].households
  54. }

4.css

  1. .left-img1-title-two {
  2. width: 27vw;
  3. margin: 0 1.875rem;
  4. .content {
  5. display: flex;
  6. justify-content: space-around;
  7. margin-bottom: 1.25rem;
  8. .bg1 {
  9. width: 14.375rem;
  10. height: 6.25rem;
  11. background: url('../assets/img/1.png') no-repeat;
  12. background-size: 14.375rem 6.25rem;
  13. display: flex;
  14. justify-content: space-around;
  15. align-items: center;
  16. text-align: center;
  17. img {
  18. width: 3.125rem;
  19. height: 3.125rem;
  20. }
  21. .shou {
  22. color: white;
  23. }
  24. .text {
  25. color: aqua;
  26. }
  27. }
  28. .bg2 {
  29. width: 14.375rem;
  30. height: 6.25rem;
  31. background: url('../assets/img/2.png') no-repeat;
  32. background-size: 14.375rem 6.25rem;
  33. display: flex;
  34. justify-content: space-around;
  35. align-items: center;
  36. text-align: center;
  37. img {
  38. width: 3.125rem;
  39. height: 3.125rem;
  40. }
  41. .shou {
  42. color: white;
  43. }
  44. .text {
  45. color: aqua;
  46. }
  47. }
  48. }
  49. .content1 {
  50. display: flex;
  51. justify-content: space-around;
  52. margin-bottom: 1.875rem;
  53. .bg1 {
  54. width: 14.375rem;
  55. height: 6.25rem;
  56. background: url('../assets/img/3.png') no-repeat;
  57. background-size: 14.375rem 6.25rem;
  58. display: flex;
  59. justify-content: space-around;
  60. align-items: center;
  61. text-align: center;
  62. img {
  63. width: 3.125rem;
  64. height: 3.125rem;
  65. }
  66. .shou {
  67. color: white;
  68. }
  69. .text {
  70. color: aqua;
  71. }
  72. }
  73. .bg2 {
  74. width: 14.375rem;
  75. height: 6.25rem;
  76. background: url('../assets/img/4.png') no-repeat;
  77. background-size: 14.375rem 6.25rem;
  78. display: flex;
  79. justify-content: space-around;
  80. align-items: center;
  81. text-align: center;
  82. img {
  83. width: 3.125rem;
  84. height: 3.125rem;
  85. }
  86. .shou {
  87. color: white;
  88. }
  89. .text {
  90. color: aqua;
  91. }
  92. }
  93. }
  94. }

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

闽ICP备14008679号