M
M
Milana Cherevatenko2020-12-01 14:45:28
Slick
Milana Cherevatenko, 2020-12-01 14:45:28

How to link two vue-slick-carousel sliders?

I wanted to ask for help in setting up communication between two snipers made on vue-slick-carousel.

<div class="preview">
                    <VueSlickCarousel
                        ref="preview"
                        :asNavFor="$refs.miniPreview"
                        :focusOnSelect="true"
                        :fade="true"
                        :arrow="false">
                        <div class="preview-slide" v-for="image in images">
                            <img :src="image" alt="{{project.title}}">
                        </div>
                    </VueSlickCarousel>
                </div>
                <div class="mini-slider">
                    <VueSlickCarousel
                        ref="miniPreview"
                        :slidesToShow="1"
                        :variableWidth="true"
                        :focusOnSelect="true"
                        :arrow="true"
                        :centerMode="true">
                        <div class="mini-preview" v-for="image in images">
                            <img :src="image" alt="{{project.title}}">
                        </div>
                        <template #prevArrow>
                            <div class="btn-prev">
                                <i class="fas fa-chevron-left"></i>
                            </div>
                        </template>
                        <template #nextArrow>
                            <div class="btn-next">
                                <i class="fas fa-chevron-right"></i>
                            </div>
                        </template>
                    </VueSlickCarousel>
                </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-12-01
@LightSwitch

:asNavFor="$refs.miniPreview"

Why it doesn't work, as the documentation suggests :
$refsare only populated after the component has been rendered, and are not reactive. This is meant only as a workaround for directly manipulating descendants - you should avoid accessing $refsfrom templates or computed properties.

As a workaround, you can force the component to update after mounting, so that the sliders will get the correct references when re-rendering:
mounted() {
  this.$nextTick(this.$forceUpdate);
},

https://jsfiddle.net/kpvwcsz7/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question