[Vuejs]-Component not handling empty prop

3👍

You can set a default prop like this.

   export default {
     props: {
        isShown: {
        type: Object,
        default: true
       }
    }
}

Default will be taken when no props are passed.

0👍

For Vue3 with the composite API you can set default props like this:

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  props: {
    isShown: {
      type: boolean,
      default: true
    },
  },
  setup() {},
})
</script>

And with the script setup

<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    isShown: boolean
  }>(),
  {
    isShown: true
  }
)
</script>
👤Johnny

Leave a comment