FleetCart/Themes/Storefront/resources/assets/public/js/mixins/DynamicTabsMixin.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-06-11 12:14:03 +00:00
export default {
data() {
return {
tabs: [],
activeTab: null,
loading: false,
products: [],
};
},
mounted() {
this.tabs = this.$children.filter((component) => {
return component.$options.name === "DynamicTab";
});
// Show the first tab by default on page load.
this.change(this.tabs[0]);
},
methods: {
classes(tab) {
return {
"tab-item": true,
loading: this.activeTab === tab && this.loading,
active: this.activeTab === tab && !this.loading,
};
},
2023-12-03 14:07:47 +00:00
async change(activeTab) {
2023-06-11 12:14:03 +00:00
if (this.activeTab === activeTab || activeTab === undefined) {
return;
}
this.loading = true;
this.activeTab = activeTab;
2023-12-03 14:07:47 +00:00
const response = await axios.get(activeTab.url);
2023-06-11 12:14:03 +00:00
2023-12-03 14:07:47 +00:00
if (this.selector().hasClass("slick-initialized")) {
this.selector().slick("unslick");
}
this.products = response.data;
this.loading = false;
2023-06-11 12:14:03 +00:00
2023-12-03 14:07:47 +00:00
this.$nextTick(() => {
this.selector().slick(this.slickOptions());
2023-06-11 12:14:03 +00:00
});
},
},
};