Skip to content

Commit 567e418

Browse files
Update options when a different object is passed.
1 parent 9b1907c commit 567e418

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

dist/js/vue-splide.cjs.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,10 @@ const _sfc_main$1 = vue.defineComponent({
26182618
default: "div",
26192619
type: String
26202620
},
2621-
options: Object,
2621+
options: {
2622+
default: {},
2623+
type: Object
2624+
},
26222625
extensions: Object,
26232626
transition: Function,
26242627
hasTrack: {
@@ -2627,7 +2630,6 @@ const _sfc_main$1 = vue.defineComponent({
26272630
}
26282631
},
26292632
setup(props, context) {
2630-
const { options } = props;
26312633
const splide = vue.ref();
26322634
const root = vue.ref();
26332635
vue.onMounted(() => {
@@ -2641,13 +2643,11 @@ const _sfc_main$1 = vue.defineComponent({
26412643
var _a;
26422644
(_a = splide.value) == null ? void 0 : _a.destroy();
26432645
});
2644-
if (options) {
2645-
vue.watch(() => merge({}, options), (options2) => {
2646-
if (splide.value) {
2647-
splide.value.options = options2;
2648-
}
2649-
}, { deep: true });
2650-
}
2646+
vue.watch(() => merge({}, props.options), (options) => {
2647+
if (splide.value) {
2648+
splide.value.options = options;
2649+
}
2650+
}, { deep: true });
26512651
vue.provide(SPLIDE_INJECTION_KEY, splide);
26522652
const index = vue.computed(() => {
26532653
var _a;

dist/js/vue-splide.esm.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,10 @@ const _sfc_main$1 = defineComponent({
26152615
default: "div",
26162616
type: String
26172617
},
2618-
options: Object,
2618+
options: {
2619+
default: {},
2620+
type: Object
2621+
},
26192622
extensions: Object,
26202623
transition: Function,
26212624
hasTrack: {
@@ -2624,7 +2627,6 @@ const _sfc_main$1 = defineComponent({
26242627
}
26252628
},
26262629
setup(props, context) {
2627-
const { options } = props;
26282630
const splide = ref();
26292631
const root = ref();
26302632
onMounted(() => {
@@ -2638,13 +2640,11 @@ const _sfc_main$1 = defineComponent({
26382640
var _a;
26392641
(_a = splide.value) == null ? void 0 : _a.destroy();
26402642
});
2641-
if (options) {
2642-
watch(() => merge({}, options), (options2) => {
2643-
if (splide.value) {
2644-
splide.value.options = options2;
2645-
}
2646-
}, { deep: true });
2647-
}
2643+
watch(() => merge({}, props.options), (options) => {
2644+
if (splide.value) {
2645+
splide.value.options = options;
2646+
}
2647+
}, { deep: true });
26482648
provide(SPLIDE_INJECTION_KEY, splide);
26492649
const index = computed(() => {
26502650
var _a;

examples/src/components/ReactivityExample.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
</template>
3737

3838
<script lang="ts">
39-
import { Splide, SplideSlide, Options } from '@splidejs/vue-splide';
40-
import { defineComponent, reactive } from 'vue';
39+
import { Options, Splide, SplideSlide } from '@splidejs/vue-splide';
40+
import { defineComponent, reactive, ref } from 'vue';
4141
import { generateSlides } from '../utils';
4242
4343

src/js/components/Splide/Splide.vue

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<script lang="ts">
1212
import { ComponentConstructor, Options, Splide } from '@splidejs/splide';
13-
import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, provide, Ref, ref, watch } from 'vue';
13+
import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, provide, Ref, ref, watch, onUpdated } from 'vue';
1414
import { EVENTS } from '../../constants/events';
1515
import { SPLIDE_INJECTION_KEY } from '../../constants/keys';
1616
import { merge } from '../../utils';
@@ -39,7 +39,10 @@ export default defineComponent( {
3939
/**
4040
* Options for Splide instance.
4141
*/
42-
options: Object as PropType<Options>,
42+
options: {
43+
default: {},
44+
type : Object as PropType<Options>,
45+
},
4346
4447
/**
4548
* Registers extension components.
@@ -61,7 +64,6 @@ export default defineComponent( {
6164
},
6265
6366
setup( props, context ) {
64-
const { options } = props;
6567
const splide = ref<Splide>();
6668
const root = ref<HTMLElement>();
6769
@@ -77,13 +79,11 @@ export default defineComponent( {
7779
splide.value?.destroy();
7880
} );
7981
80-
if ( options ) {
81-
watch( () => merge( {}, options ), options => {
82-
if ( splide.value ) {
83-
splide.value.options = options;
84-
}
85-
}, { deep: true } );
86-
}
82+
watch( () => merge( {}, props.options ), options => {
83+
if ( splide.value ) {
84+
splide.value.options = options;
85+
}
86+
}, { deep: true } );
8787
8888
provide<Ref<Splide | undefined>>( SPLIDE_INJECTION_KEY, splide );
8989

0 commit comments

Comments
 (0)