Home > Web Front-end > JS Tutorial > body text

Introduction to using the provide/inject method for Vue multi-level components

php中世界最好的语言
Release: 2018-06-01 10:39:05
Original
1121 people have browsed it

This time I will introduce to you the use of provide/inject method for Vue multi-level components. What are the precautions for using provide/inject for Vue multi-level components? The following are practical cases. , let’s take a look.

Vue official warning:

provide and inject mainly provide use cases for high-level plug-ins/component libraries. Not recommended for use directly in application code.

Of course, a warning is just a warning, you can use it normally.

The usage method is very similar to the combined gift package of data and props:

var Provider = {
 provide: {
 foo: 'bar'
 },
 // ...
}
var Child = {
 inject: ['foo'],
 created () {
 console.log(this.foo) // => "bar"
 }
 // ...
}
Copy after login
The only difference is that you don’t have to pass it in layer by layer. The event-bus used in the past can solve the problem of deep layers. problem, but it will cause the entire event-emit composition to be too confusing and difficult to maintain. Using provide / inject can ensure the clarity of parent-child unidirectional data flow.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to use vue to implement the 2048 mini game

How to use VeeValidate to perform form validation in the vue project Check function

The above is the detailed content of Introduction to using the provide/inject method for Vue multi-level components. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!