Skip to content

defineProps默认值是否可以这样规定 #12950

You must be logged in to vote

Yes, you can do this :)

Playground

<script setup lang="ts">
const { foo = { a: 1 }, bar = 1 } = defineProps<{
  foo: { a: number };
  bar: number;
}>();

// This compiles to:
const _ = {
  // ...
  props: {
    foo: { type: Object, required: true, default: () => ({ a: 1 }) },
    bar: { type: Number, required: true, default: 1 },
  },
  // ...
};
</script>

Replies: 2 comments

You must be logged in to vote
0 replies
Answer selected by bike2024

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants