W
W
WebDev2018-05-24 15:15:11
Slick
WebDev, 2018-05-24 15:15:11

How to change slide set in vue-slick?

I'm using the vue-slick carousel, which is initialized at startup. There is an "add slide" button, after which you need to "restart" the slider. But nowhere is it said how to do it. I try to use in the method of adding a slide this.$refs.slick.$reSlick(), nothing happens. How to update the slider?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-05-24
@kirill-93

I'm using vue-slick carousel...

I take it you are talking about this one ?
There is an "add slide" button, after which you need to "restart" the slider. <...> I try to use in the method of adding a slide this.$refs.slick.$reSlick(), nothing happens.

Which is not surprising - inside reSlick, the carousel is destroyed and immediately created. When destroyed, all internal markup except for images is cut out, while slick keeps the images in a separate div - that is, the newly added slide falls into the root element of slick and is immediately deleted.
So the order of actions when changing a set of slides should look something like this - destroy the carousel, change the markup, create the carousel. That is, the call $refs.slick.destroy; then changing the data on which the slide layout is built; and finally, the call $refs.slick.createwrapped in $nextTick.
I don’t see much point in doing such nonsense, it’s better to destroy and re-create an instance of the component itself. To do this, assign it a key, whose value will depend on the set of data on the basis of which the slide layout is built. For example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question