Skip to content

Commit d2a7f3e

Browse files
committed
Add reactivity on clones.
1 parent 27fedaa commit d2a7f3e

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/components/vueperslides/vueperslide.vue

+16-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ export default {
5959
})
6060
},
6161
62+
beforeUpdate () {
63+
if (this.shouldSkipUpdate || !Object.values(this.$slots).length) return
64+
65+
this.updateSlide({
66+
titleSlot: this.$slots['slide-title'],
67+
contentSlot: this.$slots['slide-content'],
68+
style: ((this.$el.attributes || {}).style || {}).value
69+
})
70+
},
71+
6272
watch: {
6373
image () {
6474
if (!this.clone) this.updateSlide({ image: this.image })
@@ -107,7 +117,6 @@ export default {
107117
const prevSlideIndex = (this.$parent.slides.current - 1 + this.slidesCount) % this.slidesCount
108118
const nextSlideIndex = (this.$parent.slides.current + 1) % this.slidesCount
109119
110-
// Index starts at 1 so this.slideIndex.
111120
if (this.slideIndex === prevSlideIndex) return faces[(4 + this.$parent.slides.current - 1) % 4]
112121
else if (this.slideIndex === nextSlideIndex) return faces[(this.$parent.slides.current + 1) % 4]
113122
@@ -141,6 +150,12 @@ export default {
141150
},
142151
justDragged () {
143152
return this.$parent.touch.justDragged
153+
},
154+
shouldSkipUpdate () {
155+
return (
156+
this.clone || !this.conf.infinite ||
157+
(!this.conf.slideContentOutside && !this.conf.alwaysRefreshClones)
158+
)
144159
}
145160
}
146161
}

src/components/vueperslides/vueperslides.vue

+3-19
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
:content="lastSlide.content"
2929
:image="lastSlide.image"
3030
:link="lastSlide.link"
31-
:style="conf.refreshClonesOnDrag ? getLastSlideStyle() : lastSlide.style"
31+
:style="lastSlide.style"
3232
aria-hidden="true")
3333
template(v-if="lastSlide.titleSlot" slot="slide-title")
3434
vnodes(:vnodes="lastSlide.titleSlot")
@@ -42,7 +42,7 @@
4242
:content="firstSlide.content"
4343
:image="firstSlide.image"
4444
:link="firstSlide.link"
45-
:style="conf.refreshClonesOnDrag ? getFirstSlideStyle() : firstSlide.style"
45+
:style="firstSlide.style"
4646
aria-hidden="true")
4747
template(v-if="firstSlide.titleSlot" slot="slide-title")
4848
vnodes(:vnodes="firstSlide.titleSlot")
@@ -142,7 +142,7 @@ export default {
142142
transitionSpeed: { type: [Number, String], default: 600 },
143143
pauseOnHover: { type: Boolean, default: true },
144144
infinite: { type: Boolean, default: true },
145-
refreshClonesOnDrag: { type: Boolean, default: false },
145+
alwaysRefreshClones: { type: Boolean, default: false },
146146
parallax: { type: [Boolean, Number], default: false },
147147
touchable: { type: Boolean, default: true },
148148
preventYScroll: { type: Boolean, default: false },
@@ -232,22 +232,6 @@ export default {
232232
this.$emit(name, ...args)
233233
},
234234
235-
getFirstSlideStyle () {
236-
const domElement = (this.$slots.default[0] || {}).elm
237-
if (!domElement) return ''
238-
239-
const { attributes: { style: { value = '' } = {} } = {} } = domElement
240-
return value
241-
},
242-
243-
getLastSlideStyle () {
244-
const domElement = (this.$slots.default[this.$slots.default.length - 1] || {}).elm
245-
if (!domElement) return ''
246-
247-
const { attributes: { style: { value = '' } = {} } = {} } = domElement
248-
return value
249-
},
250-
251235
getSlideData (index) {
252236
const slide = this.slides.list[index]
253237
let data = {}

0 commit comments

Comments
 (0)