And react the components communicate vue

Communication Components

view

  • Property transfer
  • Publish-Subscribe (EventBus): $ on / $ emit
  • Provied / inject
  • slot
  • $parent / $children
  • vuex
    react
  • Attributes
  • Publish and subscribe
  • React.createContext
  • redux / react-redux / mobix / dva

By property transfer, property transfer What is the problem: the child can only be passed to the parent, the child can not be passed to a parent

  • Child can achieve to pass the Father, the child can change a parent (vue property + Publish-Subscribe): vue subscribe achieved by publishing a parent change child: a subscription method at his father, in the yard trigger the execution by $ emit, can trigger the execution of his son something passed father
  • react pass through the callback function: from father to son through the property
    sub-reform Father: father his own way as when the property passed to his son, the father of methods to get the son, son in the method performed
    react need to achieve their own publication subscriptions, vue comes The n / on/ EMIT mode
    Therefore,in the real project, by VUE + property based publish-subscribe communication components implemented Sons
    react Sons achieved by a communication property callback +

Communication ancestor and descendant various elements:
the Provide / or react the Inject the createContext,
the descendants of all elements of information used in the context of put all ancestor elements, the descendant elements want to use when directly used
A and B common ancestors, a and B communication: the information to the ancestors, a and B can get information (trouble) in the ancestor

Providing slots vue slot, when the retrieval assembly, to separate the components pass some information

Communication between any component: only use local storage solutions
vuex, redux state of public administration (presence of virtual memory, performance optimization) a refresh gone:
localStorage (exists browser) persistent storage: app home page to display the data , (Home content does not often change, about 10min): to Locastorage deposit when the settings are stored time out when the count at the time, more than 10Min re going server to obtain 5 trillion.
the cookie he can set the time, but is limited in size 4k: client stores
session server storage
server settings session, the server returns to the client information, with the header in response to set-cookie = 'connect sid' current client and server to establish sessionId uniquely identified.
After the client to get value, information will grow to a local cookie, "httponly" can only see, can not change
the client again when the server sends a request, it will default in the request header to connect sid cookies sent to the server
cookie can and server passed around, session time server settings are cookie expiration time (the same)

Here Insert Picture Description

Published 149 original articles · won praise 5 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_26327971/article/details/105167265