Skip to content

Commit

Permalink
fix(default-theme): carousel not refresh when cross selling change tab (
Browse files Browse the repository at this point in the history
#1979)

* fix(default-theme): carousel not refresh when cross selling change tab

* fix(default-theme): use nextTick
  • Loading branch information
quando1910 committed Feb 3, 2023
1 parent af7564c commit 7f9befc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/default-theme/src/components/SwProductCarousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export default {
},
}
},
methods: {
refresh () {
if (this.$refs.carousel.glide) {
this.$nextTick(() => {
this.$refs.carousel.glide.update();
});
}
}
},
beforeDestroy() {
if (this.$refs.carousel.glide) {
this.$refs.carousel.glide.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<div v-if="crossSellCollection.length" class="products__recomendations">
<SfLoader :loading="isLoading">
<div class="products-recomendations__section">
<SfTabs :open-tab="1">
<SfTabs :open-tab="1" @click:tab="changeTab">
<SfTab
v-for="crossSellItem in crossSellCollection"
:key="crossSellItem.crossSelling.id"
:title="getTranslatedProperty(crossSellItem.crossSelling, 'name')"
>
<SwProductCarousel :products="crossSellItem.products" />
<SwProductCarousel ref="carousels" :products="crossSellItem.products" />
</SfTab>
</SfTabs>
</div>
Expand Down Expand Up @@ -39,9 +39,17 @@ export default {
},
setup(props) {
const isLoading = ref(false)
const carousels = ref(null);
const changeTab = (e) => {
carousels.value[e - 1]?.refresh();
}
if (props.crossSellings) {
const crossSellCollection = computed(() => props.crossSellings || [])
return {
carousels,
changeTab,
crossSellCollection,
isLoading,
getTranslatedProperty,
Expand Down Expand Up @@ -73,7 +81,10 @@ export default {
})
isLoading.value = false
})
return {
carousels,
changeTab,
crossSellCollection,
isLoading,
getTranslatedProperty,
Expand Down

0 comments on commit 7f9befc

Please sign in to comment.