Skip to content

Instantly share code, notes, and snippets.

@MichaelGitArt
Last active May 27, 2021 19:10
Show Gist options
  • Save MichaelGitArt/5b25e8d29368109be9ce539d5f6dd03b to your computer and use it in GitHub Desktop.
Save MichaelGitArt/5b25e8d29368109be9ce539d5f6dd03b to your computer and use it in GitHub Desktop.
Vue
<template>
<!-- https://forum.vuejs.org/t/recursive-scoped-slots/8220/6?u=michaelgitart -->
<wrapper>
<b-table v-bind="$attrs" v-on="$listeners">
<!-- Pass on all named slots -->
<slot v-for="slot in Object.keys($slots)" :name="slot" :slot="slot"/>
<!-- Pass on all scoped slots -->
<template v-for="slot in Object.keys($scopedSlots)" :slot="slot" slot-scope="scope"><slot :name="slot" v-bind="scope"/></template>
</b-table>
</wrapper>
</template>
<template>
<!-- https://dev.to/kouts/create-wrapper-components-for-vuetify-components-2aah -->
<ParentComponent>
<template v-for="(_, scopedSlotName) in $scopedSlots" #[scopedSlotName]="slotData">
<slot :name="scopedSlotName" v-bind="slotData" />
</template>
<template v-for="(_, slotName) in $slots" #[slotName]>
<slot :name="slotName" />
</template>
</ParentComponent>
</template>
export default {
install(Vue) {
console.log('install!');
const points = {
xl: 1199,
lg: 991,
md: 767,
sm: 575,
xs: 419,
xxs: 359,
};
const breakpoints = Vue.observable({
xl: null,
lg: null,
md: null,
sm: null,
xs: null,
xxs: null,
});
const breakpointsMedia = {
xl: 'only screen and (max-width: ' + points.xl + 'px)',
lg: 'only screen and (max-width: ' + points.lg + 'px)',
md: 'only screen and (max-width: ' + points.md + 'px)',
sm: 'only screen and (max-width: ' + points.sm + 'px)',
xs: 'only screen and (max-width: ' + points.xs + 'px)',
xxs: 'only screen and (max-width: ' + points.xxs + 'px)',
};
const listener = {};
for (const key in breakpoints) {
const locKey = key;
listener[key] = function (q) {
breakpoints[locKey] = q.matches;
};
const media = window.matchMedia(breakpointsMedia[key]);
media.addListener(listener[key]);
listener[key](media);
}
Vue.mixin({
beforeCreate() {
this.$breakpoints = breakpoints;
},
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment