快应用轮播组件

╰+哭是因爲堅強的太久メ 2023-07-16 02:32 81阅读 0赞
  1. <template>
  2. <div class="carousel-item">
  3. <swiper indicator="false"
  4. style="{
  5. {`height:${height};width:${width};`}}"
  6. onchange="handleChange"
  7. index="{
  8. {index}}"
  9. interval="{
  10. {interval}}"
  11. duration="{
  12. {duration}}"
  13. vertical="{
  14. {vertical}}"
  15. previousmargin="{
  16. {previousmargin}}"
  17. nextmargin="{
  18. {nextmargin}}"
  19. loop="{
  20. {loop}}"
  21. autoplay="{
  22. {autoplay}}">
  23. <div class="carousel-item__image"
  24. for="(i,n) in list">
  25. <image onclick="handleLookDateil(n)"
  26. src="{
  27. {n.src}}"></image>
  28. </div>
  29. </swiper>
  30. <div class="carousel-indicator"
  31. style="{
  32. {`margin-top:${distance}px`}}">
  33. <block for="(i,n) in list">
  34. <div class="carousel-indicator__item"
  35. style="{
  36. {imageIndex===i?activeStyls:styleStr}}">
  37. </div>
  38. </block>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. imageIndex:0
  47. }
  48. },
  49. props: {
  50. list: {
  51. type: Array,
  52. default: [
  53. {
  54. id: "111", //对应的页面id
  55. src:`http://img3.imgtn.bdimg.com/it/u=1977473038,4194935805&fm=26&gp=0.jpg` //图片路径
  56. },
  57. {
  58. id: "222", //对应的页面id
  59. src:`http://img2.imgtn.bdimg.com/it/u=3511654728,3153281898&fm=26&gp=0.jpg` //图片路径
  60. },
  61. {
  62. id: "333", //对应的页面id
  63. src:`http://img2.imgtn.bdimg.com/it/u=3511654728,3153281898&fm=26&gp=0.jpg` //图片路径
  64. },
  65. ]
  66. },
  67. styleStr: {
  68. type: String,
  69. default: `width: 40px;height: 5px;background-color: red;`
  70. },
  71. activeStyls: {
  72. type: String,
  73. default: `width: 40px;height: 5px;background-color: blue;`
  74. },
  75. height:{
  76. type:String,
  77. default:'300px'
  78. },
  79. width:{
  80. type:String,
  81. default:'100%'
  82. },
  83. index:{
  84. type:Number,
  85. default:0
  86. },
  87. autoplay:{
  88. type:Boolean,
  89. default:false,
  90. },
  91. interval:{
  92. type:Number,
  93. default:3000
  94. },
  95. loop:{
  96. type:Boolean,
  97. default:true
  98. },
  99. duration:{
  100. type:Number
  101. },
  102. vertical:{
  103. type:false
  104. },
  105. previousmargin:{
  106. type:String,
  107. default:'0px'
  108. },
  109. nextmargin:{
  110. type:String,
  111. default:'0px'
  112. },
  113. distance:{
  114. type:[Number,String],
  115. default:20
  116. }
  117. },
  118. handleChange(data) {
  119. this.imageIndex = data.index
  120. },
  121. handleLookDateil(n) {
  122. this.$emit('look', n)
  123. }
  124. }
  125. </script>
  126. <style lang="less" scoped>
  127. .carousel-item {
  128. flex-direction: column;
  129. width: 100%;
  130. swiper {
  131. /* height: 200px; */
  132. .carousel-item__image {
  133. image {
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. }
  139. .carousel-indicator {
  140. margin-top: 20px;
  141. justify-content: center;
  142. align-item: center;
  143. width: 100%;
  144. height: 40px;
  145. .carousel-indicator__item {
  146. width: 40px;
  147. height: 5px;
  148. /* border-radius: 20px; */
  149. background-color: red;
  150. margin-right: 10px;
  151. }
  152. .active {
  153. background-color: blue;
  154. }
  155. }
  156. }
  157. </style>

发表评论

表情:
评论列表 (有 0 条评论,81人围观)

还没有评论,来说两句吧...

相关阅读

    相关 vue写组件

    写轮播组件的思路: 1、确定传入的参数:轮播图的数据(图片地址,跳转href,图片ID,标题等基础数据)、轮询时间 2、写好轮播图的基本样式,父组件传入参数,动态加载进

    相关 Vue——图片组件

    Notices: 这是我一个项目中的一个子组件,要展示的数据、图片地址等的都在父组件data中。所以后面的讲述都是基于从父组件获取的参数进行处理。(如需将这个SlideShow