Home >Web Front-end >Vue.js >How to use props and emit in Vue3
Usage: When a type of component needs to be used multiple times, each call is only different in a specific place, just like A personal profile form, the information filled in by the person is different every time, but the structure is the same.
Introduce the sub-component into the parent component, pass the parameters through the label attribute of the sub-component, and define a props option in the sub-component to receive it When using it, please note that there is no need to define it in advance in the subcomponent outside of props.
##Note:
In addition, after testing, this method can only be used in data and cannot be used in setup
emit use
As shown in the figure below, props is the information passed by the parent component to the child component as mentioned above, as shown in the figure below
Now the focus is on emit, emit is a thing in context
As shown in the configuration in the parent component APP.vue, a function xxx is bound to the sub-component
Now come to the sub-component. A button is bound to an event in the sub-component to trigger the event of the parent component. xxx1 and passed a string " " back,
Finally got the following effect, every time the button in the sub-component StDent is clicked , a string attribute in the parent component will automatically add two and display them
emit summary: After the above example, we only need to know that emit is a function that allows child components to trigger parent components.
The above is the detailed content of How to use props and emit in Vue3. For more information, please follow other related articles on the PHP Chinese website!