search
HomeWeb Front-endJS TutorialDetailed graphic explanation of Vue.js

Detailed graphic explanation of Vue.js

Mar 07, 2018 am 10:45 AM
javascriptvue.jsGraphics and text

This time I will bring you a detailed explanation of Vue.js with pictures and text. What are the precautions when using Vue.js? Here are practical cases, let’s take a look.

Vue.js is currently one of the most popular and promising front-end frameworks. It provides a new thinking model that helps us quickly build and develop front-end projects. This article aims to help everyone understand Vue.js, understand the development process of Vue.js, and further understand how to build a medium-to-large front-end project through Vue.js, while doing corresponding deployment and optimization work.

The article will be developed in the form of a PPT picture with text introduction, and will not involve the specific code of the knowledge point, just click there. Interested students can check the corresponding documents to learn more.

Introduction to Vue.js

Detailed graphic explanation of Vue.js

From the introduction in the picture above, it is not difficult to find that Vue.js is a lightweight It is a data-driven front-end JS framework. The biggest difference between it and jQuery is that jQuery changes the display of the page by manipulating the DOM, while Vue realizes the update and display of the page by manipulating data. The following is the Vue data-driven conceptual model:

Detailed graphic explanation of Vue.js

Vue.js is mainly responsible for the green cube ViewModel in the picture above, which is between the View layer (i.e. DOM layer) and The Model layer (that is, the JS logic layer) is bound to DOM Listeners and Data Bingings through ViewModel, two things equivalent to listeners.

When the view of the View layer changes, Vue will listen and change the data of the Model layer through DOM Listeners. On the contrary, when the data of the Model layer changes, it will also listen and change the display of the View layer through Data Bingings. This implements a two-way data binding function, which is also the principle of Vue.js data driver.

Vue instance

Detailed graphic explanation of Vue.js

##In an html file, we can directly introduce Vue through the script tag. js, and then you can write Vue.js code in the page. In the picture above, we construct a Vue instance through new Vue(). In the instance, it can include hanging elements (el), data (data), templates (template), methods (methods) and

lifecycleHooks (created, etc.) and other options. Different instance options have different functions, such as:

(1) el indicates which area under the element our Vue needs to operate, and '#demo' indicates the area under the element with the ID of demo.

(2) data represents the data object of the Vue instance, and the attributes of data can respond to data changes.
(3) created indicates the step in the instance life cycle when the creation is completed. When the instance has been created, its method will be called.

Vue common instructions

Detailed graphic explanation of Vue.js

In the development of Vue projects, the one we use most should be It is a Vue command. Through the common instructions provided by Vue, we can fully utilize the powerful functions of Vue's data drive. The following is a brief introduction to the commonly used instructions in the figure:

(1) v-text: used to update the content in the bound element, similar to jQuery's text() method

(2) v- html: used to update the html content in the bound element, similar to jQuery's html() method
(3) v-if: used to render the element based on the true and false conditions of the value of the expression, if P3 in the above picture is If false, the P tag will not be rendered
(4) v-show: Used to display hidden elements based on the true and false conditions of the expression value, and switch the display CSS attribute of the element
(5) v-for: Use For traversing data to render elements or templates, if P6 in the figure is [1,2,3], 3 P tags will be rendered, and the contents are 1, 2, 3
(6) v-on: used in the element Binding events, the click event of showP3 is bound to the P tag in the figure

For more Vue instructions, you can view the Vue2.0 document, address: https://vuefe.cn/api/# Instructions

Vue.js Technology Stack

Detailed graphic explanation of Vue.js

We mentioned above that you can write Vue code directly in an HTML page by introducing Vue.js, but this method is not commonly used. Because if our project is relatively large, there will be many pages in the project. Once each page introduces a Vue.js or declares a Vue instance, this is very detrimental to later maintenance and code sharing, and there will also be instance name conflicts. situation, so we need to use the technology stack provided by Vue to build a powerful front-end project.

In addition to Vue.js, we also need to use:

(1) vue-cli: Vue’s scaffolding tool, used to automatically generate the directories and files of the Vue project.
(2) vue-router: The front-end routing tool provided by Vue, we use it to implement page routing control, partial refresh and on-demand loading, build a single-page application, and achieve front-end and back-end separation.
(3) vuex: The state management tool provided by Vue is used to manage the interaction and reuse of various data in our projects at the same time, and stores the data objects we need to use.
(4) ES6: A new version of Javascript, short for ECMAScript6. Using ES6 we can simplify our JS code while taking advantage of the powerful features it provides to quickly implement JS logic.
(5) NPM: The node.js package management tool is used to uniformly manage the packages, plug-ins, tools, commands, etc. needed in our front-end projects to facilitate development and maintenance.
(6) webpack: A powerful file packaging tool that can package and compress our front-end project files into js at the same time, and can achieve syntax conversion and loading through loaders such as vue-loader.
(7) Babel: A plug-in that converts ES6 code into browser-compatible ES5 code

Using the above technologies, we can start building our Vue project.

Building large-scale applications

Detailed graphic explanation of Vue.js

##In building our medium and large Vue projects, we mainly introduce how to Use vue-cli to automatically generate the front-end directory and files of our project, understand the concept that everything in Vue is a component and the communication issues of parent-child components, explain how we use third-party plug-ins in the Vue project, and finally use webpack to package and deploy us s project.

vue-cli build

Detailed graphic explanation of Vue.js

Before using vue-cli we need to install node.js and use the npm command it provides to install vue-cli. To install node.js, you only need to go to its official website to download the software and install it. The address is: https://nodejs.org/en/

After the installation is completed, we open the cmd command line tool of the computer and enter the above picture in sequence. Commands in:

(1) npm install -g vue-cli: Install vue-cli globally

(2) vue init webpack my-project: Use vue-cli to generate a webpack-based project at the directory address The Vue project file and directory named 'my-project'
(3) cd my-project: Open the folder just created
(4) npm intall: Install the package files that the project depends on
(5) npm run dev: Use the local node server to open and browse the project page in the browser

In this way, our vue project directory based on webpack is built.

Single file component

Detailed graphic explanation of Vue.js##In the vue project just built, we will find an App .vue and Hello.vue files, then files ending with the .vue suffix like this are common single-file components in our Vue projects. A single file component contains the html, js, and css of a function or module. In the .vue file, we can write html in the template tag, js in the script tag, and css in the style tag. Such a function or module is a .vue component, which is also very convenient for component sharing and later maintenance.

Parent-child component communication

Detailed graphic explanation of Vue.js So like this in the development of projects with single-file components as the core , we will definitely think of a question, that is, how do vue parent and child components exchange data to achieve communication? Props are provided in Vue2.0 to enable parent components to pass data to child components, and $emit is used to enable child components to pass data to parent components. Of course, if it is a more complex and common data interaction, it is recommended that you use vuex to manage the data uniformly. For details, please see: https://vuefe.cn/guide/components.html#Use Props to pass data

Plug-in usage

Detailed graphic explanation of Vue.js

Next we will introduce how we use plug-ins in webpack-based vue projects. There are two main situations:

(1) Global use

(1) Introduced in index.html: This method is not recommended because there is a problem with the loading order, and some plug-ins do not support this method.
(2) Introduction through webpack configuration file: Mainly implemented through the webpack.ProvidePlugin() method of the plugin configuration item, but it is only suitable for plugins that support the CommonJs specification and provide a global variable, such as in jQuery $.
(3) Introduction through import + Vue.use(): This method requires importing the plug-in that needs to be loaded in the global .vue file, and then implementing it through Vue.use('plug-in variable name'), but this method Only plug-ins that follow Vue.js plug-in writing specifications are supported, such as vue-resourece.

(2) Single file use

(1) Direct introduction through import: This method can be used in .vue files that need to call plug-ins, but you need to pay attention to the order of creation of instances. , or it can also be introduced through require.

(2) import + components registration: This method is the way of using Vue components. You can register and use a sub-component in a component.

Deployment and Optimization

1Detailed graphic explanation of Vue.js

After we have completed the front-end coding phase of the entire Vue project, we need to The main ways to deploy and optimize our front-end project files are as follows:

(1) Use webpack's DefinePlugin to specify the production environment: Through the DefinePlugin configuration in the plugin, we can declare 'process.env ' attribute is 'development' (development environment) or 'production' (production environment). It is very convenient to switch the environment mode by combining the scripts command in the npm configuration file package.json.

(2) Use UglifyJs to automatically delete warning statements in code blocks: Generally used in the webpack configuration file of the production environment, configured through new webpack.optimize.UglifyJsPlugin(), deleting warning statements can reduce the file size volume of.

(3) Use Webpack hash to process cache: When we need to modify a file published online, if the recompiled file name is the same as the previous version, the browser will not recognize it and load the cache file. The problem. In this way we need to automatically generate file names with hash values ​​to prevent caching. For details, see: https://segmentfault.com/a/1190000006178770#articleHeader7

(4) Use v-if to reduce unnecessary component loading: The v-if instruction is actually very useful, it can make our project Components that are not needed temporarily will not be rendered and will be rendered when they are needed, such as a pop-up window component, etc. This way we can reduce the first load time and file size of the page.

In addition to the optimization of the above points, there are many optimization options. Interested children can take a good look at the API documentation of webpack. After all, webpack is very powerful.

Data-driven examples

1Detailed graphic explanation of Vue.js

#Summary

This article is attached with PPT pictures The form of text introduction briefly introduces the knowledge points and development process of Vue.js, and runs the concepts of front-end automation, componentization, and engineering throughout it. It explains Vue.js's "simple but yet simple" concept from shallow to deep. The unique charm of "Elegance without losing elegance, compactness without being too big"

I believe you have mastered the method after reading these cases. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Related reading:

Using Video.js to implement the H5 live broadcast interface

detailed explanation of the path module of node.js

The above is the detailed content of Detailed graphic explanation of Vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript: Exploring the Versatility of a Web LanguageJavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor