Reputation: 89
<script lang="ts" setup>
interface Props {
bigArray: string[];
}
***const props = withDefaults(defineProps<Props>(), {
bigArray:[],
}*** <---- Here is the error, setting props
const bigArray = ref(props.BigArray);
</script>
BigArray?: string[] | null;
Looking for the proper way to set up an empty array as a prop in this scenario:
Upvotes: 2
Views: 2933
Reputation: 719
import { withDefaults, defineProps} from "vue";
interface Props {
bigArray?: string[]
}
const props = withDefaults(defineProps<Props>(), {
bigArray: () => []
})
console.log(props.bigArray);
You just needed to add the () =>
arrow-function for it to work.
This is shown here in the vue documentation.
And if you want to make the prop optional (as it should be with a default value) use ?
after the variable-name. This will ensure there are no unnecessary warnings in the console.
Upvotes: 10