search
HomeSystem TutorialLINUXIntroduction to the classic and easy-to-use JavaScript framework Vue.js

Introduction to the classic and easy-to-use JavaScript framework Vue.js

Sep 02, 2024 pm 03:05 PM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

This article aims to introduce a useful JavaScript framework Vue.js, so that readers can have a preliminary understanding of it.

What is Vue

Vue (pronounced /vjuː/, similar to view) is a progressive framework for building user interfaces. Unlike other large frameworks, Vue is designed to be applied layer by layer from the bottom up. Vue's core library only focuses on the view layer, which is not only easy to get started, but also easy to integrate with third-party libraries or existing projects. On the other hand, when combined with a modern tool chain and various supporting libraries, Vue is fully capable of providing drivers for complex single-page applications.

Features of Vue - Computed Properties

Writing expressions in Vue templates is very convenient, but if you put complex logic in it, the template will be bulky and difficult to maintain. For complex logic, Vue provides calculated properties to solve it.

<div id="example">
<p>Original message: "{{ message }}"</p>
<p>Computed reversed message: "{{ reversedMessage }}"</p>
</div>

var vm = new Vue({
el: '#example',
data: {
message: 'Hello'
},
computed: {
reversedMessage: function () {
return this.message.split('').reverse().join('')
}
}
})

This is a basic example of a computed property, which will output:

Original message: "Hello"
Computed reversed message: "olleH"

A computed property reversedMessage is declared here, and the function we provide in computed will be used as the value of the property vm.reversedMessage. And when vm.message changes, vm.reversedMessage will also change accordingly, and if there are other properties related to it, it will also change accordingly.

Vue’s methods and calculated properties

Actually, this is very similar to the method. We can use the method to achieve the same effect, similar to this

<div id="example">
<p>Original message: "{{ message }}"</p>
<p>Computed reversed message: "{{ reversedMessage() }}"</p>
</div>var vm = new Vue({
el: '#example',
data: {
message: 'Hello'
},
methods: {
reversedMessage: function () {
return this.message.split('').reverse().join('')
}
}
})

You can get the same result like this, but the difference from the calculated property is that as long as the message does not change, the calculated property will not execute the function, but directly return the previous result; while the method needs to execute the function repeatedly. Use methods when you don't need caching.

Vuex, Vue’s core plug-in

Let’s answer a question first: What is Vuex?

Vuex is a state management pattern developed specifically for Vue.js applications. It uses centralized storage to manage the status of all components of the application, and uses corresponding rules to ensure that the status changes in a predictable way. Vuex is also integrated into Vue's official debugging tool devtools extension, which provides advanced debugging functions such as zero-configuration time-travel debugging, state snapshot import and export, etc.

Basic ideas of Vuex state management

Extract the shared state of the component and manage it in a global singleton mode. In this mode, our component tree forms a huge "view". No matter where it is in the tree, any component can obtain status or trigger behavior

In addition, by defining various concepts in isolation state management and enforcing certain rules, our code will become more structured and easier to maintain.

This idea borrows from Flux, Redux, and The Elm Architecture. Unlike other patterns, Vuex is a state management library designed specifically for Vue.js to take advantage of Vue.js's fine-grained data response mechanism for efficient state updates.

经典好用的JavaScript框架Vue.js 简介

When should I use Vuex?

Although Vuex can help us manage shared state, it also comes with more concepts and frameworks. This requires weighing short- and long-term benefits.

If you don’t plan to develop a large single-page application, using Vuex may be cumbersome and redundant. It's true - if your application is simple enough, it's better not to use Vuex. A simple global event bus is enough. However, if you need to build a medium to large single-page application, you will probably consider how to better manage state outside the component, and Vuex will become a natural choice.

Comparison of Vue and other plug-ins

Let’s take React as an example for comparison. First of all, they both have many similarities:

Use Virtual DOM
Provides responsive (Reactive) and componentized (Composable) view components.
Keep the focus on the core library and leave other functions such as routing and global state management to related libraries.

Runtime performance

In a React application, when the state of a component changes, it will re-render the entire component subtree with the component as the root.

In Vue applications, component dependencies are automatically tracked during the rendering process, so the system can accurately know which components really need to be re-rendered. You can understand that every component has automatically obtained shouldComponentUpdate, and there is no restriction on the subtree problem mentioned above.

This feature of Vue eliminates the need for developers to consider such optimizations and allows them to better focus on the application itself.

About web program

In React, everything is JavaScript. Not only HTML can be expressed using JSX, but the current trend is increasingly incorporating CSS into JavaScript for processing. This type of approach has its advantages, but there are also trade-offs that not every developer is comfortable with. In React, all component rendering functionality relies on JSX. JSX is a tool for writing JavaScript using XML syntax.

The whole idea of ​​Vue is to embrace classic web technologies and expand on them. In fact, Vue also provides rendering functions and even supports JSX. However, our default recommendation is templates. Any valid HTML is a valid Vue template. For many developers who are used to HTML, templates are more natural to read and write than JSX. Of course there is an element of subjective preference here, but if this difference will lead to an improvement in development efficiency, then it has objective value.

Scale

Both Vue and React provide powerful routing to handle large applications. The React community is very innovative in state management (such as Flux, Redux), and these state management patterns and even Redux itself can be easily integrated into Vue applications. In fact, Vue has taken this model (Vuex) one step further and integrated Vue's state management solution Vuex more deeply. I believe it can bring you a better development experience.

Another important difference between the two is that Vue’s routing library and state management library are officially maintained and supported and updated synchronously with the core library. React chooses to leave these issues to the community, thus creating a more decentralized ecosystem. But relatively, React's ecosystem is more prosperous than Vue.

There are other differences between React and Vue, which I won’t go into details here. Of course, which one to choose may depend on the user. What we are doing at this time is just a few suggestions for convenience. Users have a better understanding of Vue and how it is different from other plug-ins.

The above is the detailed content of Introduction to the classic and easy-to-use JavaScript framework 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
Warehouse: A GUI for Effortlessly Handling Flatpak AppsWarehouse: A GUI for Effortlessly Handling Flatpak AppsMay 09, 2025 am 11:30 AM

A GUI for Effortless Flatpak Management: Introducing Warehouse Managing a growing collection of Flatpak applications can be cumbersome using only the command line. Enter Warehouse, a user-friendly graphical interface designed to streamline Flatpak a

8 Powerful Linux Commands to Identify Hard Drive Bottlenecks8 Powerful Linux Commands to Identify Hard Drive BottlenecksMay 09, 2025 am 11:03 AM

This article provides a comprehensive guide to identifying and resolving hard drive bottlenecks in Linux systems. Experienced server administrators will find this particularly useful. Slow disk operations can severely impact application performance,

4 Best QR Code Generators for Linux Users4 Best QR Code Generators for Linux UsersMay 09, 2025 am 10:27 AM

Efficient QR code generation tool under Linux system In today's digital world, QR codes have become a way to quickly and conveniently share information, simplifying data access from URLs, texts, contacts, Wi-Fi credentials, and even payment information. Linux users can use a variety of tools to create QR codes efficiently. Let's take a look at some popular QR code generators that can be used directly on Linux systems. QRencode QRencode is a lightweight command line tool for generating QR codes on Linux. It is well-received for its simplicity and efficiency and is popular with Linux users who prefer direct methods. Using QRencode, you can use the URL,

elementary OS 8: A User-Friendly Linux for macOS and Windowselementary OS 8: A User-Friendly Linux for macOS and WindowsMay 09, 2025 am 10:19 AM

Elementary OS 8 Circe: A Smooth and Stylish Linux Experience Elementary OS, a Ubuntu-based Linux distribution, has evolved from a simple theme pack into a fully-fledged, independent operating system. Known for its user-friendly interface, elegant de

40  Linux Commands for Every Machine Learning Engineer40 Linux Commands for Every Machine Learning EngineerMay 09, 2025 am 10:06 AM

Mastering Linux is crucial for any machine learning (ML) engineer. Its command-line interface offers unparalleled flexibility and control, streamlining workflows and boosting productivity. This article outlines essential Linux commands, explained fo

Arch Linux Cheat Sheet: Essential Commands for BeginnersArch Linux Cheat Sheet: Essential Commands for BeginnersMay 09, 2025 am 09:54 AM

Arch Linux: A Beginner's Command-Line Cheat Sheet Arch Linux offers unparalleled control but can feel daunting for newcomers. This cheat sheet provides essential commands to confidently manage your system. System Information & Updates These com

How to Install Scikit-learn for Machine Learning on LinuxHow to Install Scikit-learn for Machine Learning on LinuxMay 09, 2025 am 09:53 AM

This guide provides a comprehensive walkthrough of installing and using the Scikit-learn machine learning library on Linux systems. Scikit-learn (sklearn) is a powerful, open-source Python library offering a wide array of tools for various machine l

How to Install Kali Linux Tools in UbuntuHow to Install Kali Linux Tools in UbuntuMay 09, 2025 am 09:46 AM

This guide explains how to leverage Docker for accessing Kali Linux tools, a safer and more efficient alternative to outdated methods like Katoolin. Katoolin is no longer actively maintained and may cause compatibility problems on modern systems. Do

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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