Dependency injection
Advantages:
- The ancestor component does not need to know which descendant components use the properties it provides;
- Descendant components do not need to know where the injected property came from;
Disadvantages:
- The coupling between components is relatively close and difficult to reconstruct;
- The supplied properties are non-reactive;
Source code analysis
Vue.prototype._init is invoked when the component instance is initialized, and the vm._init calls initInjections before data/props and initProvide after data/props
initInjections
This method mainly does the following two things:
- Obtain vm.$options.inject and find the corresponding key set by resolveInject.
- Iterate over the key set and respond to it;
resolveInject
This method realizes that the parent node data can be looked up by $parent.
- $parent = $parent; $parent = $parent
initProvide
This method simply assigns the component’s registered provide value to vm._provided, used in resolveInject
Vue series of courses
Vue source code analysis will be conducted in succession recently, a series of courses are as follows:
The state series
- Principle of props
- Principle of the methods
- Principle of the data
- Principles of the computed
- Watch the principle
Lifecycle series
- Life cycle principle
The event series
- Principle of the event
Render series
- Render principle
Inject/dojo.provide series
- Inject/dojo.provide principle
The plugins series
- Vue – principle of the router
- Vue Router stuff
- Vuex something you should know
- Vue source code analysis of vuex principle
- Vue custom plug-in
Component series
- Keep alive – principle
- Vue single file component
- Communication between Vue components
- Vue virtual list
Series of instructions
- Vue custom command
- Caching principles for vue source code parsing
The algorithm series
- Principle of diff
- Vue compiler source code analysis
Asynchronous tasks
- NextTick principle of vUE source code parsing
other
- Vue unit tests
- Vue multicast components
- Things you didn’t know about Vue
- Vue skills big decryption
- Interview – VUE data responsive implementation of advanced front-end