Detailed explanation of Vue multi-level components New method Provide / Inject

Provide / INJECT is a new approach to 2.2, which can be injected into all future generations (one content) with a ancestor component.

Provider / INJECT: Simplely provides variables via Provider in the parent component, and then injects variables in subcaps.

VUE official warning:

Provide and INJECT are mainly used for high-order plug-in / component libraries. It is not recommended to use it directly in the application code.

Of course, the warning is just a warning, you can use it when you are using it.

Usage Methods It is very like a combination of Data and PROPS:

VAR Provider = {provide: {foo: ‘bar’}, //. ..} var child = {incject: [‘foo’], created () {console.log (this.foo) // => “bar”} // …}
  The only difference is that you don't have to be incorporated by another layer. Although the Event-Bus in the past can solve deep problems, it will cause the entire EVENT-EMIT composition to be too confusing, it is difficult to maintain. Use Provide / Inject to ensure the clarity of the parent-child one-way data stream.  
In the React’s Provider / Consumer, there is the same effect. Since it is not used, there is only one side of the react itself, and it is understood later, and the classmates who are interested can read the documentation.
Reference article:

VUE official document

Province / inject in Vue 2.2

The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Clouds.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment