A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

Preface

Since vue3.0 was officially launched, many friends have switched to vue3.0. Here I will write down the principles of 3.0 and 2.0 and the differences between them that I have summarized for your own learning.

Step 1: The responsive principle of vue2.0

First look at the explanation on the official website:

When you pass a plain JavaScript object to the data option of a Vue instance, Vue will iterate over all the properties of the object and convert them all to getters/setters using Object.defineProperty. Object.defineProperty is an unshimmable feature in ES5, which is why Vue does not support IE8 and lower versions of browsers.

These getters/setters are invisible to the user, but internally they allow Vue to track dependencies and notify changes when properties are accessed or modified. The problem that needs to be noted here is that the browser console formats getter/setter differently when printing data objects, so you may need to install vue-devtools to get a more friendly inspection interface.

Each component instance has a corresponding watcher instance object, which records the properties as dependencies during component rendering. Later, when the setter of the dependency is called, the watcher is notified to recalculate, thereby updating its associated components.

Here is my understanding

In fact, it is not difficult for people who have read the API and source code to know that v-model and responsive principles are divided into two layers.

  • The first layer, the bottom layer, is a feature of es5, Object.defineProperty, which updates data through getter and setter.
  • The second layer is the presentation layer. Anyone who has read the v-model principle knows that there is a watcher in the v-model. The v-onwatcher monitors the data changes and v-on updates the view.

Step 2: The responsive principle of vue3.0

First look at the explanation on the official website:

This is why vue3.0 can directly delete and modify object properties.

Step 3: Summarize the differences between the two

----------- 3.0

(The first two no longer need to be set to change like in 2.0. They can be changed directly)

1. 3.0 proxy can directly change the data of array type

2. You can directly add and delete object attributes

3.3.0 is compatible with IE12 and above

4. The v-model syntax on the component is changed to v-bind.sync

5. The priority of using v-for and v-if on the same element has changed

6. The key usage on v-for has been changed

7. The ref of v-for is no longer registered as an array

8, destroyed, beforeDestroy lifecycles are renamed to unmounted and beforeUnmount

9, <template> is treated as a normal element, not as content inside the renderer

Here are the major changes released on the official website

Summarize

This is the end of this article about the responsive principles and differences of vue2.0/3.0. For more relevant content on the responsive principles of vue2.0/3.0, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue2.x responsiveness simple explanation and examples
  • Vue2 implements provide inject to deliver responsiveness
  • Learn a little bit about Vue's data responsiveness (the difference between Vue2 and Vue3)
  • Implementing the responsive adaptive carousel component plug-in VueSliderShow function based on Vue2x
  • A brief discussion on the basic ideas of implementing Vue2.0 responsiveness
  • 100 lines of code to understand and analyze the vue2.0 responsive architecture
  • Vue2 responsive system asynchronous queue

<<:  Detailed explanation of nginx upstream configuration and function

>>:  Installation tutorial of mysql 8.0.11 compressed version under win10

Recommend

Detailed explanation of fs module and Path module methods in Node.js

Overview: The filesystem module is a simple wrapp...

Analysis of product status in interactive design that cannot be ignored in design

In the process of product design, designers always...

How to implement remote connection for Redis under Linux

After installing Redis on Linux, use Java to conn...

Vue project @change multiple parameters to pass multiple events

First, there is only one change event. changeleve...

MySQL learning notes help document

View system help help contents mysql> help con...

Detailed explanation of Vue element plus multi-language switching

Table of contents Preface How to switch between m...

The difference between html Frame, Iframe and Frameset

10.4.1 The difference between Frameset and Frame ...

How to use libudev in Linux to get USB device VID and PID

In this article, we will use the libudev library ...

Vue2/vue3 routing permission management method example

1. There are generally two methods for Vue routin...

Docker time zone issue and data migration issue

Latest solution: -v /usr/share/zoneinfo/Asia/Shan...

How to introduce img images into Vue pages

When we learn HTML, the image tag <img> int...

Examples of using the or statement in MySQL

1. The use of or syntax in MySQL, and the points ...