What is? mixins( Mix in )?

mixins That's right vue An extension of component , Some common data or methods will be used , Build a data structure that can be mixed in , By different vue Component , Can be in different vue Components use the same method or basic data .

A little understanding vue Mingled students , You may be confused ,mixins and vue Or vuex Very similar .

mixins and vuex The difference between .

vuex Public state management , After a component is introduced , If the component changes vuex Data status inside , Other introductions vuex Data components will also be modified accordingly , be-all vue Components are applied in the same file vuex data .( stay js in , It's kind of like a shallow copy )
vue introduce mixins data ,mixins Data or method , It is independent in each component , Non interfering , All belong to vue Component itself .( stay js in , It's kind of like deep copy )

mixins The difference between common components and common components
General data and methods , It's really possible to come up with a generic component , Shared by parent-child components in the form of parameters .

Common components

Subcomponents pass props Receive from parent component ( Common components ) Parameters or methods of , but vue Not recommended , Direct modification of subcomponents props Data received from the parent component . It needs to be in the data Medium or computed Define a field in the to receive .( It's a bit of a problem )
The main function of common components is to reuse the same vue assembly ( There are views , There are ways , Stateful ).

mixins
If we just extract common data or common methods , And these data or methods , No maintenance between components is required , You can use it mixins.( be similar to js Some common methods encapsulated in )

Technology
Daily Recommendation