2
2
<div v-if =" data.length" >
3
3
<div ref =" myGallery" class =" my-gallery" :data-pswp-uid =" radom" >
4
4
<div v-if =" slides.length" >
5
- <div :key =" radom + '_' + index" v-for =" (l ,index) in slides" >
6
- <img preview :src =" l" alt =" " >
7
- </div >
5
+ <div :key =" radom + '_' + index" v-for =" (l, index) in slides" ><img preview :src =" l" alt =" " /></div >
8
6
</div >
9
7
</div >
10
- <div
11
- ref =" pswpWrap"
12
- class =" pswp"
13
- tabindex =" -1"
14
- role =" dialog"
15
- aria-hidden =" true" >
8
+ <div ref =" pswpWrap" class =" pswp" tabindex =" -1" role =" dialog" aria-hidden =" true" >
16
9
<div class =" pswp__bg" ></div >
17
10
<div class =" pswp__scroll-wrap" >
18
11
<div class =" pswp__container" >
29
22
<button class =" pswp__button pswp__button--zoom" title =" Zoom in/out" ></button >
30
23
<div class =" pswp__preloader" >
31
24
<div class =" pswp__preloader__icn" >
32
- <div class =" pswp__preloader__cut" >
33
- <div class =" pswp__preloader__donut" ></div >
34
- </div >
25
+ <div class =" pswp__preloader__cut" ><div class =" pswp__preloader__donut" ></div ></div >
35
26
</div >
36
27
</div >
37
28
</div >
38
29
<div class =" pswp__share-modal pswp__share-modal--hidden pswp__single-tap" >
39
30
<div class =" pswp__share-tooltip" ></div >
40
31
</div >
41
- <button class =" pswp__button pswp__button--arrow--left" title =" Previous (arrow left)" >
42
- </button >
43
- <button class =" pswp__button pswp__button--arrow--right" title =" Next (arrow right)" >
44
- </button >
45
- <div class =" pswp__caption" >
46
- <div class =" pswp__caption__center" ></div >
47
- </div >
32
+ <button class =" pswp__button pswp__button--arrow--left" title =" Previous (arrow left)" ></button >
33
+ <button class =" pswp__button pswp__button--arrow--right" title =" Next (arrow right)" ></button >
34
+ <div class =" pswp__caption" ><div class =" pswp__caption__center" ></div ></div >
48
35
</div >
49
36
</div >
50
37
</div >
@@ -61,7 +48,9 @@ import PhotoSwipe from 'photoswipe/dist/photoswipe'
61
48
import PhotoSwipeUIDefault from ' photoswipe/dist/photoswipe-ui-default'
62
49
/** 生成随机字符串 */
63
50
function createId () {
64
- return Math .random ().toString (36 ).substring (2 )
51
+ return Math .random ()
52
+ .toString (36 )
53
+ .substring (2 )
65
54
}
66
55
export default {
67
56
name: ' PreviewImage' ,
@@ -127,22 +116,22 @@ export default {
127
116
})
128
117
const loadingInstance = Loading .service ()
129
118
const galleryElement = this .$refs .myGallery
130
- this .radom = createId ();
119
+ this .radom = createId ()
131
120
let pswpElement = this .$refs .pswpWrap
132
121
const items = await this .transThumbnailElements ()
133
122
let photoSwipeOptions = {
134
123
galleryUID: this .radom ,
135
- getThumbBoundsFn : function (index ) {
124
+ getThumbBoundsFn : function (index ) {
136
125
let thumbnail = items[index].el
137
126
let pageYScroll = window .pageYOffset || document .documentElement .scrollTop
138
127
let rect = thumbnail .getBoundingClientRect ()
139
128
return {
140
129
x: rect .left ,
141
130
y: rect .top + pageYScroll,
142
- w: rect .width
131
+ w: rect .width ,
143
132
}
144
133
},
145
- ... options
134
+ ... options,
146
135
}
147
136
this .gallery = new PhotoSwipe (pswpElement, PhotoSwipeUIDefault, items, photoSwipeOptions)
148
137
this .gallery .init ()
@@ -159,17 +148,17 @@ export default {
159
148
},
160
149
async getWH (elem ) {
161
150
return new Promise ((resolve , reject ) => {
162
- if (typeof elem .naturalWidth === " undefined" ) {
151
+ if (typeof elem .naturalWidth === ' undefined' ) {
163
152
// IE 6/7/8
164
153
let img = new window.Image ()
165
154
img .src = elem .getAttribute (' src' )
166
- img .onload = function () {
155
+ img .onload = function () {
167
156
resolve ({
168
157
w: this .width ,
169
158
h: this .height ,
170
159
})
171
160
}
172
- img .onerror = function () {
161
+ img .onerror = function () {
173
162
reject ({
174
163
w: 0 ,
175
164
h: 0 ,
@@ -182,7 +171,7 @@ export default {
182
171
h: elem .naturalHeight ,
183
172
})
184
173
} else {
185
- elem .onload = function () {
174
+ elem .onload = function () {
186
175
resolve ({
187
176
w: this .naturalWidth ,
188
177
h: this .naturalHeight ,
@@ -217,7 +206,7 @@ export default {
217
206
destroy () {
218
207
// 销毁
219
208
if (this .gallery ) {
220
- this .gallery .close ();
209
+ this .gallery .close ()
221
210
this .gallery = null
222
211
}
223
212
},
0 commit comments