Web interview: The difference between MVC and MVVM and why Vue does not fully comply with MVVM

Web interview: The difference between MVC and MVVM and why Vue does not fully comply with MVVM

Difference between MVC and MVVM

aforementioned

First of all, these two are just a thought, a design pattern

Many programming languages ​​have designed many frameworks based on this idea, such as SpringMVC in Java, ThinkPHP in PHP, Vue, React, Angular in JavaScript, etc.

MVC

Overview

1. Data should be rendered to the view
Defining a template engine
Get the data
Then render the data into the template engine

2. View Action Controller
Add a click event to the button on the page
Calling methods in events
The controller then sends a request to modify the data

3. Send network requests to modify data through methods
Then send a network request to get the modified data
Then render the data to the view

Pros and Cons

advantage:

Reduce coupling and facilitate code maintenance and expansion

shortcoming:

After each data update, DOM needs to be operated, which affects development efficiency;

MVVM

Overview

Preface

In order to improve development efficiency, a new idea emerged: MVVM. Its biggest feature: two-way data binding;

When the data in M ​​changes, the data in V will automatically change. When the data in V changes, the data in M ​​will automatically change.

MVVM is an advancement of MVC and a replacement for MVC.

Features:

When M changes, V changes automaticallyWhen V changes, M changes automatically

relation:

Once M changes, VM will detect the change of M and automatically modify V

Once V changes, VM will detect the change in V and automatically modify M

With MVVH, all DOM operations are performed by VM, which reduces the workload of programmers. Programmers can spend a lot of time on business logic instead of DOM operations.

MVVM Implementer — Vue

insert image description here

Why doesn’t Vue fully comply with MVVM?

insert image description here

The original words come from the author's statement on the Vue official website, but the author did not give a reason. According to my own research and sorting, I think there are two reasons

Reason 1: MVVM refers to "Model-View-ViewModel", which should completely decouple the "model" and "view", but Vue provides a property: ref, through which you can get the DOM object and directly operate the view. This violates mvvm;

Reason 2: As shown in the figure below, structurally, the "data layer" is included in the "data model layer", and the two parts are not completely independent.

insert image description here

The above is the detailed content of the difference between MVC and MVVM in web interviews and the answer to why Vue does not fully comply with MVVM. For more information about MVC and MVVM, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Notes on Vue.js and MVVM
  • A brief analysis of the MVVM implementation principle in Vue
  • A brief discussion on the MVC and MVVM structures of JavaScript front-end development
  • Explanation of mvvm mode in vue
  • Detailed explanation of the MVVM principle and implementation method in Vue

<<:  How to solve the slow speed of MySQL Like fuzzy query

>>:  Nginx anti-crawler strategy to prevent UA from crawling websites

Recommend

js implements the classic minesweeper game

This article example shares the specific code of ...

Realize super cool water light effect based on canvas

This article example shares with you the specific...

Detailed explanation of the principles and usage of MySQL stored procedures

This article uses examples to explain the princip...

Detailed explanation of the use of $emit in Vue.js

1. Parent components can use props to pass data t...

Mysql transaction concurrency problem solution

I encountered such a problem during development A...

VMware installation of Centos8 system tutorial diagram (Chinese graphical mode)

Table of contents 1. Software and system image 2....

How to use VIM editor in Linux

As a powerful editor with rich options, Vim is lo...

Using js to achieve waterfall effect

This article example shares the specific code of ...

Let me teach you how to use font icons in CSS

First of all, what is a font icon? On the surface...

Python Flask WeChat applet login process and login api implementation code

1. Let’s take a look at the effect first Data ret...

Detailed explanation and summary of the URL for database connection

Detailed explanation and summary of the URL for d...