reactive
itself has great limitations, which requires extra attention during use. If these problems are ignored, it will cause a lot of trouble in development; ref is more like theoption api
in the vue2 era The replacement ofdata
can store any data type, while the data type declared byreactive
can only be objects;
Let’s draw the conclusion first, and then explain the reason in detail: Don’t use reactive
unless necessary! (Official documents also have corresponding recommendations)
Official text: It is recommended to use ref()
as the main API for declaring reactive status.
The people who know Vue best have said this: Recommended ref!!!!!!
reactive
and ref
comparison
reactive |
ref |
---|---|
?Only supports objects and arrays (reference data types) | ?Supports basic data types + reference data types |
?In in code>
| |