Vue封装组件-图片轮播图-LjCarousel

今天药忘吃喽~ 2022-09-02 13:47 283阅读 0赞

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMzIzMjU2_size_16_color_FFFFFF_t_70

LjCarousel.vue:

  1. <!--LjCarousel-->
  2. <template>
  3. <div>
  4. <el-carousel
  5. ref="ref_carouselMenu"
  6. :interval="interval"
  7. :height="height"
  8. :autoplay="autoplay"
  9. indicator-position="none"
  10. :style="{ width: width }"
  11. >
  12. <el-carousel-item v-for="(item, index) in imgs" :key="index" :name="item">
  13. <el-image :src="item"></el-image>
  14. </el-carousel-item>
  15. </el-carousel>
  16. <div :style="imgListStyle">
  17. <el-image
  18. v-for="(item, index) in imgs"
  19. :key="index"
  20. :src="item"
  21. @click="$refs.ref_carouselMenu.setActiveItem(item)"
  22. :style="imgItemStyle"
  23. ></el-image>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. name: "LjCarousel",
  30. components: {},
  31. props: {
  32. //显示的图片数组
  33. imgs: {
  34. type: Array,
  35. default: () => [],
  36. required: true,
  37. },
  38. //轮播间隔
  39. interval: {
  40. type: Number,
  41. default: 4000,
  42. },
  43. //大图片高度
  44. height: {
  45. type: String,
  46. default: "250px",
  47. },
  48. //大图片宽度
  49. width: {
  50. type: String,
  51. default: "400px",
  52. },
  53. autoplay: {
  54. type: Boolean,
  55. default: true,
  56. },
  57. //小图片最大高度
  58. maxHeight: {
  59. type: String,
  60. default: "60px",
  61. },
  62. //小图片最大宽度
  63. maxWidth: {
  64. type: String,
  65. default: "60px",
  66. },
  67. // 小图片布局
  68. justifyContent: {
  69. type: String,
  70. default: "start",
  71. },
  72. },
  73. data() {
  74. return {
  75. imgListStyle: {
  76. display: "flex",
  77. justifyContent: this.justifyContent,
  78. gap: "10px",
  79. width: this.width,
  80. marginTop: "15px",
  81. },
  82. imgItemStyle: {
  83. cursor: "pointer",
  84. maxHeight: this.maxHeight,
  85. maxWidth: this.maxWidth,
  86. },
  87. };
  88. },
  89. computed: {},
  90. created() {},
  91. mounted() {},
  92. filters: {},
  93. methods: {},
  94. watch: {},
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. .LjCarousel {
  99. }
  100. </style>

使用:

2021080317150281.png watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMzIzMjU2_size_16_color_FFFFFF_t_70 1

imgs:图片数组。必传

  1. <LjCarousel
  2. :imgs="imgs_treeType"
  3. :interval="4000"
  4. height="250px"
  5. width="400px"
  6. :autoplay="true"
  7. maxHeight="60px"
  8. maxWidth="60px"
  9. justifyContent="start"
  10. ></LjCarousel>

发表评论

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

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

相关阅读

    相关 vue组件

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

    相关 Vue——图片组件

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