In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis of the type of props stolen by vue. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Type of props stolen
Copy prop types from child components just to use them in the parent component. But stealing these prop types is much better than just copying them.
For example, we Icon uses a component in this component:
{{heading}}
To make it work, we need to add the correct prop type and copy it from the Icon component:\
Import Icon from'. / Icon' Export default {components: {Icon}, props: {iconType: {type: String, required: true,}, iconSize: {type: String, default: 'medium', validator: size = > [' small', 'medium',' large', 'xMuthlarge'] .colors (size), iconColour: {type: String Default: 'black',}, heading: {type: String, required: true,}
When the prop type of the Icon component is updated, you are sure you will forget to go back to the component and update them. Over time, as the prop type of the component begins to deviate from the prop type in the component, an error Icon will be introduced.
So that's why we steal them:
Import Icon from'. / Icon';export default {components: {Icon}, props: {... Icon.props, heading: {type: String, required: true,}
Except in our example, we added "icon" at the beginning of each prop name, so we had to do some extra work to do this:
Import Icon from'. / Icon';const iconProps = {}; / / Do some processing beforehandObject.entries (Icon.props). ForEach ((key, val) = > {iconProps [`icon$ {key [0] .toUpperCase ()} ${key.substring (1)} `] = val;}); export default {components: {Icon}, props: {... iconProps, heading: {type: String, required: true,}
Now, if the prop type in the Icon component is modified, our component will remain up to date.
But what if a prop type is added or removed from the Icon component? To cover these situations, we can use v-bind computing props to stay dynamic.
This is the end of this article on "sample Analysis of the types of props stolen by vue". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.