In vuejs, data-driven means that when the data changes, the user interface changes accordingly, and developers do not need to manually modify the DOM; simply speaking, it changes the DOM by controlling changes in data. , allowing the content of the view (DOM) to change as the data changes.
The operating environment of this tutorial: Windows 7 system, vue version 2.9.6, DELL G3 computer.
1: What is Vue, how to understand Vue
Vue is a framework based on the MVVM mode data-driven page, which binds data on view. It is a technology for implementing single-page applications.
Several major features summarized:
Simple
Lightweight
Fast
Data-driven
Module-friendly
Component-based
Vue relies on data-driven two-way binding to make it easier for us to develop pages. Developers do not need to manually modify the DOM. Vue makes everything easier with two-way data binding. Its data-driven two-way binding is implemented through the data set and get function principles defined by Object.defineProperty().
2. Component-based development makes the project more scalable and portable, and the code is more reusable.
3. Single-page application experience, local components update the interface to make the user experience faster and save time.
Single-page application, also known as SPA, limits all activities to a Web page and only loads the corresponding HTML, JavaScript and CSS when the Web page is initialized. After the loading is completed, the page no longer reloads or jumps. Only the components or modules inside interact and jump through hash or history api, and pull data through ajax to implement the response function. The entire application is just one html, so it is called Single Page!
4. The js code is invisibly standardized, and the code developed through teamwork is more readable.
2: What is the principle of Vue data-driven (two-way data binding)?
What is data-driven
Data-driven is the biggest feature of vue.js. In vue.js, the so-called data-driven means that when the data changes, the user interface changes accordingly, and developers do not need to manually modify the DOM.
For example, if we click a button, the text of the element needs to be switched between yes and no. In jquery, when modifying the page, we generally follow this process. We bind events to the button, then obtain the element dom object corresponding to the copy, and then modify the copy value of the dom object according to the switch.
So how does vuejs achieve this data drive?
Vue implements two-way data binding mainly by using data hijacking combined with the publisher-subscriber model, and using Object.defineProperty() to hijack the setters and getters of each property when the data changes. Publish messages to subscribers and trigger corresponding listening callbacks. When you pass a plain Javascript object to a Vue instance as its data option, Vue will iterate through its properties and convert them into getters/setters using Object.defineProperty. The getters/setters are not visible to the user, but internally they allow Vue to track dependencies and notify changes when properties are accessed and modified.
Vue's two-way data binding uses MVVM as the entrance to data binding, integrating Observer, Compile and Watcher. It uses Observer to monitor the data changes of its own model, and uses Compile to parse and compile template instructions (vue is used to parse {{}}), and finally uses watcher to build a communication bridge between observer and Compile to achieve data changes -> view updates; view interactive changes (input) -> data model changes in both directions Binding effect.
Understanding of getter/setter?
When printing out the attributes in the data object under the Vue instance, each of its attributes has two corresponding get and set methods. As the name implies, get is for value acquisition and set is for assignment. Under normal circumstances, we take Value and assignment are done using obj.prop, but there is a problem with this. How do I know that the value of the object has changed? So it’s the set’s turn to appear. You can understand get and set as functions. When we call the properties of the object, we will enter get.property(){...} and first determine whether the object has this property. If not, then add a name attribute and assign a value to it; if there is a name attribute, return the name attribute. You can think of get as a function that takes a value, and the return value of the function is the value it gets. What I feel is more important is the set attribute. When assigning a value to an instance: At this time, it will enter set name(val){...}; the formal parameter val is the value I assigned to the name attribute. In this function, you can do a lot Things have changed, such as two-way binding! Because every change of this value must go through set, it cannot be changed by other methods, which is equivalent to a universal listener. The ES5 object prototype has two new attributes __defineGetter__ and __defineSetter__, which are specially used to bind get and set to objects. It is recommended to use the following method, because it is written on the prototype, so it can be inherited and reused.
3: MVVM framework
The data driver of Vue.js is implemented through the MVVM framework. The MVVM framework mainly contains three parts: model, view and viewmodel.
Model: refers to the data part, which corresponds to the front-end equivalent of the javascript object
View: refers to the view part, which corresponds to the front-end equivalent In dom
Viewmodel: it is the middleware communication that connects the view and the data
Data (Model) and view (View) cannot communicate directly , but the communication between the two parties needs to be realized through ViewModel. When the data changes, the viewModel can monitor the change and notify the view to make modifications in a timely manner. Similarly, when an event is triggered on the page, viewMOdel can also listen to the event and notify the model to respond. Viewmodel is equivalent to an observer, monitoring the actions of both parties and notifying the other party in time to perform corresponding operations.
Related recommendations: "vue.js Tutorial"
The above is the detailed content of How to understand vuejs data driver. For more information, please follow other related articles on the PHP Chinese website!

To integrate React into HTML, follow these steps: 1. Introduce React and ReactDOM in HTML files. 2. Define a React component. 3. Render the component into HTML elements using ReactDOM. Through these steps, static HTML pages can be transformed into dynamic, interactive experiences.

React’s popularity includes its performance optimization, component reuse and a rich ecosystem. 1. Performance optimization achieves efficient updates through virtual DOM and diffing mechanisms. 2. Component Reuse Reduces duplicate code by reusable components. 3. Rich ecosystem and one-way data flow enhance the development experience.

React is the tool of choice for building dynamic and interactive user interfaces. 1) Componentization and JSX make UI splitting and reusing simple. 2) State management is implemented through the useState hook to trigger UI updates. 3) The event processing mechanism responds to user interaction and improves user experience.

React is a front-end framework for building user interfaces; a back-end framework is used to build server-side applications. React provides componentized and efficient UI updates, and the backend framework provides a complete backend service solution. When choosing a technology stack, project requirements, team skills, and scalability should be considered.

The relationship between HTML and React is the core of front-end development, and they jointly build the user interface of modern web applications. 1) HTML defines the content structure and semantics, and React builds a dynamic interface through componentization. 2) React components use JSX syntax to embed HTML to achieve intelligent rendering. 3) Component life cycle manages HTML rendering and updates dynamically according to state and attributes. 4) Use components to optimize HTML structure and improve maintainability. 5) Performance optimization includes avoiding unnecessary rendering, using key attributes, and keeping the component single responsibility.

React is the preferred tool for building interactive front-end experiences. 1) React simplifies UI development through componentization and virtual DOM. 2) Components are divided into function components and class components. Function components are simpler and class components provide more life cycle methods. 3) The working principle of React relies on virtual DOM and reconciliation algorithm to improve performance. 4) State management uses useState or this.state, and life cycle methods such as componentDidMount are used for specific logic. 5) Basic usage includes creating components and managing state, and advanced usage involves custom hooks and performance optimization. 6) Common errors include improper status updates and performance issues, debugging skills include using ReactDevTools and Excellent

React is a JavaScript library for building user interfaces, with its core components and state management. 1) Simplify UI development through componentization and state management. 2) The working principle includes reconciliation and rendering, and optimization can be implemented through React.memo and useMemo. 3) The basic usage is to create and render components, and the advanced usage includes using Hooks and ContextAPI. 4) Common errors such as improper status update, you can use ReactDevTools to debug. 5) Performance optimization includes using React.memo, virtualization lists and CodeSplitting, and keeping code readable and maintainable is best practice.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!