In vue, vm is the abbreviation of ViewModel, which means view model and is the bridge connecting view and model; ViewModel can monitor data changes and then notify the corresponding view to automatically update, achieving two-way Binding.
The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.
VM is actually ViewModel--view model.
MVVM View-Model-ViewModel
[View] refers to the page you see, and [Model] refers to the data passed by the backend.
[View Model] The core of mvvm mode, it is the bridge connecting view and model; it has two directions:
One is: convert [Model] into [View], that is, The data passed by the backend is converted into the page seen. The way to achieve this is: data binding.
The second is: Convert [View] into [Model], that is, convert the page you see into back-end data. The way to implement it is: DOM event monitoring.
If these two directions are implemented, we call it [two-way binding] of data.
Under the MVVM framework, views and models cannot communicate directly. They communicate through ViewModel. ViewModel usually implements an observer. When the data changes, ViewModel can monitor the change in data and then notify the corresponding view to automatically update.
When the user operates the view, the ViewModel can also monitor changes in the view and then notify the data to make changes. This actually realizes two-way binding of data. And View and ViewModel in MVVM can communicate with each other.
【Related recommendation: "vue.js Tutorial"】
The above is the detailed content of What is vm in vue. For more information, please follow other related articles on the PHP Chinese website!