激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服務(wù)器之家 - 編程語言 - JavaScript - vue使用swiper實(shí)現(xiàn)左右滑動(dòng)切換圖片

vue使用swiper實(shí)現(xiàn)左右滑動(dòng)切換圖片

2021-10-27 15:23yb305小白 JavaScript

這篇文章主要為大家詳細(xì)介紹了vue使用swiper實(shí)現(xiàn)左右滑動(dòng)切換圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue使用swiper實(shí)現(xiàn)左右滑動(dòng)切換圖片的具體代碼,供大家參考,具體內(nèi)容如下

使用npm 安裝vue-awesome-swiper

?
1
npm install vue-awesome-swiper --save

在main.js中引用

?
1
2
3
import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.user(VueAwesomeSwiper)
import 'swiper/dist/css/swiper.css'

在組件中使用

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<template>
 <div>
  <label class="timeline">{{ time }}</label>
  <div id="star-pic-vue">
   <template v-if="data">
    <img
     e
     v-for="(item, index) in images"
     :src="item.url"
     :key="index"
     id="contract_url"
     @click="enlargePic(index)"
    />
    <template v-if="isDialogShow"> </template>
    <el-dialog
     :visible.sync="centerDialogVisible"
     width="100%"
     modal
     close-on-click-modal
     custom-class="dialog"
    >
     <swiper :options="swiperOption" ref="mySwiper" style="height: 100%;">
      <swiper-slide v-for="(img, index) in images" :key="index">
       <div class="swiper-zoom-container">
        <img :src="img.url" alt="" />
       </div>
      </swiper-slide>
     </swiper>
    </el-dialog>
   </template>
  </div>
 </div>
</template>
 
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
export default {
 name: "PictureComponent",
 props: ["data", "maxShow", "time"],
 data() {
  return {
   centerDialogVisible: false,
   showPic: "",
   isDialogShow: false,
   activeIndex: 1,
   startX: 0,
   swiperOption: {
    width: window.innerWidth,
    zoom: true,
    initialSlide: 0
   }
  };
 },
 computed: {
  images() {
   if (this.data instanceof Array && this.data.length > 2) {
    var value = this.data;
    return value.splice(0, this.maxShow);
   } else {
    return this.data;
   }
  }
 },
 components: {
  swiper,
  swiperSlide
 },
 methods: {
  // 放大圖片
  enlargePic(i) {
   this.activeIndex = i;
   this.isDialogShow = true;
   // 使用$refs,如果ref是定位在有v-if、v-for、v-show中的DOM節(jié)點(diǎn),
   // 返回來的只能是undefined,因?yàn)樵趍ounted階段他們根本不存在
   this.$nextTick(() => {
    var swiper = this.$refs.mySwiper.swiper;
    swiper.activeIndex = i;
   });
   this.centerDialogVisible = true;
  }
 }
};
</script>
 
<style lang="scss">
.timeline {
 display: block;
 margin: 10px 20px 5px;
}
#star-pic-vue .el-dialog__wrapper {
 position: fixed;
 top: 0;
 right: 0;
 bottom: 0;
 left: 0;
 overflow: auto;
 margin: 0;
 background: #171717;
}
#star-pic-vue {
 width: 100%;
 height: auto;
 display: flex;
 flex-wrap: wrap;
 justify-content: stretch;
 padding: 3px 13px;
 img {
  width: 82px;
  height: 80px;
  margin: 4px 0px 0px;
  padding-right: 2px;
 }
 .dialog {
  img {
   width: 100%;
   height: 100%;
   margin: 0;
  }
 }
 .el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
  height: 100%;
  width: 100%;
 }
 .el-dialog__header {
  display: none;
 }
 .el-dialog__body {
  padding: 0 !important;
  margin: 0 !important;
  height: 460px;
  background: #171717;
 }
 .el-carousel {
  height: 100%;
 }
 .el-carousel__container {
  height: 410px;
 }
 .el-carousel__indicators--outside {
  margin-top: 20px;
 }
}
</style>

效果

vue使用swiper實(shí)現(xiàn)左右滑動(dòng)切換圖片

$refs定位不到的主要原因是因?yàn)関-if、v-for、v-show這些語句如果依賴父組件傳來的參數(shù)的話,該參數(shù)是在mounted()階段子還沒獲取得到。

如果想要真正地在DOM加載完成后拿到數(shù)據(jù),就需要調(diào)用VUE的全局api : this.$nextTick(() => {})

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/yb305/article/details/103047789

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品国产乱码久久久久久丨区2区 | 中文亚洲视频 | 国产区二区 | 在线看免费观看日本 | 91九色国产视频 | 欧美高清另类自拍视频在线看 | 91网站永久免费看 | 精品亚洲午夜久久久久91 | 国产精品久久久久久久久久iiiii | 成年免费视频黄网站在线观看 | 精久久久| 91久久久久久久 | 国产一级免费片 | 欧美a在线观看 | av在线免费网址 | 成人免费观看在线视频 | 中文字幕www| av7777777| 欧美日韩a∨毛片一区 | 进去了(高h)| 粉嫩蜜桃麻豆免费大片 | 在线97视频 | 亚洲午夜影院在线观看 | 人人舔人人插 | 国产一区二区三区影视 | 成人国产精品一区 | 午夜精品福利影院 | 一级黄色大片在线观看 | chinese乱子伦xxxx国语对白 | 性生活视频网站 | 91免费大片| 国产男女爽爽爽爽爽免费视频 | 黄www片 | 91av大片 | 一级免费特黄视频 | 亚洲综合视频网站 | 精品午夜影院 | 欧美一区永久视频免费观看 | 亚洲第一页中文字幕 | 夜夜夜影院| 久久久久成人精品亚洲国产 |