1.
MVVM –Model View ViewModel
And the core of it isViewModel
。ViewModel
containsDOM Listeners
和 Data Bindings
.
Data Bindings
Used to bind data toView
On display,DOM Listeners
Used for listening operations.
-
Data Bindings, or Data Bindings, from Model to View. This saves us a lot of code and time to manually update the View.
-
DOM Listeners are event Listeners from View to Model. So our Model will change as the View fires events. Requests for data and requests for views are completely decoupled (interacting).
2. Two directions:
MVVM thinking has two directions.
- One is to convert the model into a view, which is to convert the data passed by the back end into the page you see.
The implementation is: data binding.
- The second is to convert the view into a model, which is to convert the page you see into data on the back end. This is done by DOM event listening.
Both directions are called bidirectional data binding.
3. The difference between MVC and MVVM
Mvc-model View Controller(Controller: Controller), M and V means the same as M and V in MVVM, and C refers to the page business logic. The purpose of MVC is to separate M and V code, but MVC is one-way communication, that is, to render the Model to the View, it must be connected by the Controller.
The difference between MVC and MVVM is not that the ViewModel completely replaces the Controller.
- The ViewModel is intended to remove data rendering from the Controller, not replace it.
- Other operations should still be implemented in the Controller, so that business logic components can be reused.
4. Common interview questions about Vue
- What is the MVVM idea?
Mvm-model View ViewModel, which includes DOM Listenters and Data Bindings, which implement Data bindings and automatically render pages when Data changes. The latter implements binding of data to the page, and DOM and Model changes as the page manipulates data.
- Advantages of MVVM over MVC?
- MVVM implements bidirectional binding between data and page, while MVC only implements one-way binding between Model and View.
- MVVM decouples the page business logic from the rendering, as well as the data from the view, and can be componentized.
- How does VUE embody MVVM ideas?
- Beard syntax, data and view binding.
- V-on event binding. When data is manipulated through events, the V-Model changes accordingly.