Skip to content

Commit 6682a8d

Browse files
committed
fix(images): add watch for prop
1 parent ce9527c commit 6682a8d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/components/script.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export default {
5353
select: this.startAt,
5454
thumbSelect: this.startAt,
5555
lightBoxOn: this.showLightBox,
56-
countImages: this.images.length,
5756
displayThumbs: this.images.slice(0, this.nThumbs),
5857
timer: null,
5958

@@ -62,6 +61,10 @@ export default {
6261
},
6362

6463
computed: {
64+
countImages() {
65+
return this.images.length
66+
},
67+
6568
imagesThumb() {
6669
if (this.siteLoading) {
6770
return this.displayThumbs.map(({ thumb }) => ({
@@ -75,16 +78,16 @@ export default {
7578
},
7679
},
7780

78-
mounted() {
79-
if (this.autoPlay) {
80-
this.timer = setInterval(() => {
81-
this.nextImage()
82-
}, this.autoPlayTime)
83-
}
84-
},
81+
watch: {
82+
startAt() {
83+
this.$set(this, 'select', this.startAt)
84+
this.$set(this, 'thumbSelect', this.startAt)
85+
},
8586

87+
images() {
88+
this.$set(this, 'displayThumbs', this.images.slice(0, this.nThumbs))
89+
},
8690

87-
watch: {
8891
select() {
8992
let halfDown = Math.floor(this.nThumbs / 2)
9093
let mod = 1 - (this.nThumbs % 2)
@@ -119,6 +122,14 @@ export default {
119122
},
120123
},
121124

125+
mounted() {
126+
if (this.autoPlay) {
127+
this.timer = setInterval(() => {
128+
this.nextImage()
129+
}, this.autoPlayTime)
130+
}
131+
},
132+
122133
methods: {
123134
showImage(index) {
124135
document.addEventListener('keydown', this.addKeyEvent)

0 commit comments

Comments
 (0)