[Vuejs]-Object with field "type" as type in Vue2 component

0👍

You can check if fields exist on an object and check their respective type via. validators for props like explained here in the docs: https://vuejs.org/guide/components/props.html#prop-validation

0👍

You can only check if the prop passed is an Object but you can’t check what’s inside the object as type check.
You syntax is wrong that’s why there is the error.

Example below
Inside Parent Component

<child-component
  placeholder="Enter  name"
  label="Name"
  :object-passed="{
     title: 'myTitle',
     type: 'myType'
  }"
/>

Inside Child Component

     props: {
            label: {
                type: String,
                required: false,
                default: ''
            },
            placeholder: {
                type: String,
                required: false,
                default: ''
            },
            objectPassed: {
                type: Object,
                required: true
            }
        }

Leave a comment