current position:Home>Communication mode between Vue components

Communication mode between Vue components

2022-04-29 04:29:13weixin_ forty-two million two hundred and fifty-four thousand a

vue Communication mode between components
1、props and e m i t Father Group Pieces of towards Son Group Pieces of Pass on Deliver Count According to the yes through too p r o p Pass on Deliver Of , Son Group Pieces of Pass on Deliver Count According to the to Father Group Pieces of yes through too emit The parent component passes data to the child component through prop Delivered , The child component passes the data to the parent component through emit Father Group Pieces of towards Son Group Pieces of Pass on Deliver Count According to the yes through too prop Pass on Deliver Of , Son Group Pieces of Pass on Deliver Count According to the to Father Group Pieces of yes through too emit Trigger events to do
2、 Central event bus bus
Non parent child component , newly build Vue event bus object , And then through bus. e m i t touch Hair things Pieces of , b u s . emit Triggering event ,bus. emit touch Hair things Pieces of ,bus.on Monitor triggered events
3、provide and inject
Pass... In the parent component provider To provide variables , And then in the subcomponent through inject To inject variables . You can get it no matter how deep it is
4、v-model
Parent component passed v-model When passing values to subcomponents , Will automatically send a value Of prop attribute , Pass in subcomponent this.$emit(‘input’,val) Automatically modify v-model The value of the binding
5、vuex Handle
If the business logic is complex , Many components need to process some common data at the same time , The above methods are available at this time, which may not be conducive to the maintenance of the project ,vuex The way is to extract these public data , Then other components can read and write the public data , In this way, the purpose of decoupling is achieved
6、ref obtain

copyright notice
author[weixin_ forty-two million two hundred and fifty-four thousand a],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/117/202204270551121880.html

Random recommended