N
N
nonamer_city2022-02-10 13:46:40
Vue.js
nonamer_city, 2022-02-10 13:46:40

Is it possible to check the props of an object in vue?

Hello.
Vue props have a great ability to validate input parameters such as required, type, validation and so on.
Is it possible to set such parameters for object keys?
Conditionally if I pass an object to a component.
And in props I process something like

normal props

props: {
  title: String,
  likes: Number,
  isPublished: Boolean,
}

And do something like this
props: {
  data:{
    title: {
      required:true
    },
   label: {
      required:true
    }
}
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Temur__k, 2022-02-13
@Temur__k

Probably possible.

props: {
   data: {
      type: Object,
      required: true,
      default: () => { return {} },
   }
 }

D
Dmitry Skrypnik, 2022-02-17
@Shkipon

For View props, it is possible to create your own validator function. In theory, what interests you is described in this section:
https://ru.vuejs.org/v2/guide/components-props.htm...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question