Pass and validate object to Vue 2 component

I have a Vue component with many props

<Field
        v-for="field in fields"
        :key="field.name"
        :name="field.name"
        :type="field.type"
        :label="field.label"
        :values="field.values"
        :value="field.value"
      />

      

I check it this way

 props: {
  name: {
    type: String,
    required: true
  },
  label: {
    type: String,
    required: true
  },
  type: {
    type: String,
    default: 'text'
  },
  value: {
    type: String,
    default: ''
  },
  values: [Object]
}

      

So I want to pass all properties as one object like

<Field
    v-for="field in fields"
    :key="field.name"
    :params="field"
  />

      

How can I check and return the default values ​​for the properties of this object?

+3


source to share


1 answer


<Field
  v-for="field in fields"
  :key="field.name"
  v-bind="field"
/>

      



You can bind an object and each of its properties will be passed as props using the syntax above.

+2


source







All Articles