I want to be able to set default values for nested datasets in Vue, basically, if a key does not have a value in the dataset that is being parsed to the component, I would like that value to be filled in automatically. This kinda works looking into this example here. However, my sample which is nested with several keys in the main object seems not to work. Why is that? what am I doing wrong?
Test Component
<script setup lang="ts">
import {defineProps, PropType} from 'vue';
export type KitchenType = {
windows: number;
};
export type DefaultTestType = {
kitchen?: KitchenType;
rooms?: number;
};
const props = defineProps({
dataset: {
type: Object as PropType<DefaultTestType>,
default: () => ({
kitchen: {
windows: 5,
},
rooms: 3,
})
},
});
console.log('IAM DATASET: ', props.dataset);
</script>
Calling the Component
<DefaultTest :dataset="{
rooms: 5,
}" />
Console.log result
{ rooms: 5 }
Console.log expected result
{ kitchen: { windows: 5, }, rooms: 5 }
I'm using Laravel 9 with Vite, Inertia and Vue3 and have enabled the reactivityTransform: true
in the vite.config
file as told here through here
If I don't pass any dataset object, I am getting all the default values