Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the default type of vue property props

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

The knowledge of this article "vue attributes props default type how to write" is not understood by most people, so the editor summarizes the following content to you, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "vue attributes props default type how to write" article.

Vue attribute props default type Vue.component ('my-component', {props: {/ / basic type checking (`null` matches any type) / / single type propA: Number, / / multiple possible types propB: [String, Number], / / required string propC: {type: String, required: true} / / function propC: {type:Function, required: true}, / / numeric propD with default values: {type: Number, default: 100}, / / multiple possible types with default values propE: {type: [String, Number], default: 100} / / object propF with default value: {type: Object, / / object or array and must return the default value default: function () {return {message: 'hello'} from a factory function. / / Custom validation function propG: {validator: function (value) {/ / this value must match one of the following strings return ['success',' warning', 'danger'] .indexOf (value)! =-1}) props custom attribute

1. This is a custom property. When encapsulating general components, reasonable use of props can greatly improve the reusability of components.

two。 Syntax: can be defined as an array type:

Export default {props: ['init']}

It can also be defined as an object type:

Export default {/ / props is a "custom attribute" that allows the user to specify the initial value / / the name of the custom attribute for the current component through the custom property, the data in the wrapper custom (as long as the name is legal) / / props, can be directly used in the template structure / / Note: props is read-only, do not directly modify the value of props, otherwise the terminal will report an error! / / props: ['init'], props: {/ / Custom attribute A: {/ * configuration option * /}, / / Custom property B: {/ * configuration option * /}, / / Custom property C: {/ * configuration option * /}, init: {/ / if the outside world uses the Count component If the init attribute is not passed, the default value takes effect default: 0. The value type of / / init must be Number numeric type: Number, / / required check required: true}},}

Note: array types do not have default attributes, they only exist if they are defined as object types.

The above is about the content of this article on "how to write the default type of vue attribute props". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report