The difference between props, slot, emit, and proProvide/Inject in Vue is the usage scenario

In vue3, data can be transmitted through props, slot, emit, proProvide/Inject, so which one is better to use? I think proProvide/Inject is the easiest way, so do you still need to use porps, slot, emit

In fact, in addition to these things, there is another way, which is to directly create a js file:

Suppose we have a requirement like this:

When the button is clicked, it will trigger both count ++, that is, part of the data or functions of the two components are the same. To achieve such an operation, we often do this:

Create a js file directly to write the code of vue, and then the js code does not have the function of vue components to engage in templates, so only some functions in the script are just used to bind multiple data together,

Put the js file specially used for export in the store folder, and then import and use it in the vue component that needs to bind the same data or function

Guess you like

Origin blog.csdn.net/conquer_galaxy/article/details/130030402