1.MVVM and MVC pattern

  • MVC:MVC is one of the most widely used software architectures in generalMVCCan be divided into:The Model (Model).The View (View).Controller(Controller). This is mainly for the purpose of layering, separating responsibilities from each other.ViewCommonly usedControllerWill you come andModelMake contact.ControllerisModelandViewThe coordinator of,ViewandModelNo direct contact. It’s almost a one-way connection.

1.View sends instructions to Controller.

2. The Controller changes the Model state after completing the business logic.

3.Model sends new data to the View, and the user gets feedback.

  • MVVM: MVVM changes Controller in MVC to ViewModel.

    Changes to the View are automatically updated to the ViewModel, and changes to the ViewModel are automatically synchronized to the View to display the View layer through data.

2. Advantages of MVVM pattern and differences with MVC pattern

  • Advantages of MVVM mode:

    • Low coupling: Views can be changed and modified independently of Model. A ViewModel can be bound to different views, and the Model can remain unchanged when the View changes, and the View can remain unchanged when the Model changes.
    • Reusability: You can put some View logic in a ViewModel so that many views can reuse that View logic.
    • Independent development: Developers can focus on business logic and data development, and designers can focus on page design.
  • Differences between MVVM and MVC:

    • The Controller in MVC morphed into the ViewModel in MVVM
    • MVVM shows the view layer through data rather than node operations
    • MVVM mainly solves the problem that a large number of DOM operations in MVC reduce page rendering performance, slow loading speed and affect user experience