In popular frameworks like PrimeVue or ElementPlus there is some sort of hack with slots when they are used like params for parent component, for example in DataTables. I'm trying to do something similar, but stuck with reactivity...
Currently in my parent component I have this:
<script setup>
import {onMounted, useSlots, watch, h, computed} from 'vue';
import { useDataTableStore } from '@/components/DataTable/DataTableStore';
const dataTableStore = useDataTableStore();
const slots = useSlots();
const props = defineProps({
data: {
type: Array,
required: true,
},
});
onMounted(() => {
dataTableStore.orderAll = props.orderAll;
dataTableStore.searchAll = props.searchAll;
slots.default().forEach(s => {
dataTableStore.columns.push({
title: s.props.title,
prop: s.props.prop ?? s.props.title,
order: s.props.order ?? false,
search: s.props.search ?? false,
searchType: s.props['search-type'] ?? 'text',
searchOptions: s.props['search-options'] ?? []
});
});
});
</script>
The main problem is that the props of slots are not reactive.
<DataTable
:data="packagesStore.packages"
:columns="columns"
:search-all="true"
:order-all="true"
@on-filter="onFilter"
>
<DataTableColumn
title="Nr."
prop="number"
:search="false"
/>
<DataTableColumn
title="Wood"
prop="wood.id"
search-type="select"
:search-options="classificatorsStore.quality"
/>
</DataTable/>