Default values for Vue component props & how to check if a user did not set the prop?

后端 未结 3 907
星月不相逢
星月不相逢 2021-01-30 12:26

1. How can I set the default value for a component prop in Vue 2? For example, there is a simple movies component that can be used in this way:

3条回答
  •  [愿得一人]
    2021-01-30 12:56

    Also something important to add here, in order to set default values for arrays and objects we must use the default function for props:

    propE: {
          type: Object,
          // Object or array defaults must be returned from
          // a factory function
          default: function () {
            return { message: 'hello' }
          }
        },
    

提交回复
热议问题