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

WeChat applet + ECharts to achieve dynamic refresh process record

Preface Recently I encountered a requirement, whi...

Docker renames the image name and TAG operation

When using docker images, images with both REPOSI...

How to use squid to build a proxy server for http and https

When we introduced nginx, we also used nginx to s...

Solution to the problem that the docker container cannot be stopped

The solution is as follows: 1. Force delete conta...

Detailed explanation of destructuring assignment syntax in Javascript

Preface The "destructuring assignment syntax...

WebWorker encapsulates JavaScript sandbox details

Table of contents 1. Scenario 2. Implement IJavaS...

Detailed explanation of the frame and rules attributes of the table in HTML

The frame and rules attributes of the table tag c...

Solution to the Docker container being unable to access the host port

I recently encountered a problem at work. The doc...

JavaScript to implement a simple shopping form

This article shares the specific code of JavaScri...

JS implements the sample code of decimal conversion to hexadecimal

Preface When we write code, we occasionally encou...

Design of pop-up windows and floating layers in web design

In the trend of gradual transition from tradition...

Linux server SSH cracking prevention method (recommended)

1. The Linux server configures /etc/hosts.deny to...

Javascript closure usage scenario principle detailed

Table of contents 1. Closure 2. Closure usage sce...