Table of Contents
本地引用
程序验证
Home Web Front-end Vue.js Vue.js learning record one: learning planning and understanding Vue.js

Vue.js learning record one: learning planning and understanding Vue.js

Oct 12, 2020 pm 05:15 PM
vue.js

Vue.js Tutorial column introduces learning planning and understanding Vue.js, you can learn together.

Vue.js learning record one: learning planning and understanding Vue.js

This study note will record some of the program codes and learning experiences I personally wrote when learning the Vue.js framework. To do this, I will create a directory named vuejs under the ProgrammingLanguage/JavaScript directory, and set up the following two subdirectories under this directory:

    ## The
  • #note directory is used to store notes in markdown format. The
  • code directory is used to store the program code recorded in the notes.
Learning plan

    Learning basics:
    • Master the basic knowledge related to HTML, CSS, and JavaScript. Ok, I
    • master the basic usage of npm package manager.
    • Understand the basic principles of B/S application architecture.
  • Learning materials:
    • Video tutorial: Vue.js teaching video of Dark Horse Programmer
    • Online documentation: Vue.js official tutorial
    • Reference book: "Vue.js in simple terms"
  • Learning goal:
    • Develop a "Cloud Notepad" application.
Part 1: Understanding the Vue.js Framework

This part of the notes will record my conceptual understanding of the Vue.js framework, as well as my experience in the project Introduce the specific methods of the framework and write a "Hello World" program.

Vue.js Introduction

Vue.js is a progressive framework for building user interfaces. The framework is designed to be applied layer by layer from the bottom up. Its 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.js is fully capable of driving complex single-page applications. In short, Vue.js has the following characteristics:

    uses a template syntax similar to traditional HTML, which may be easier for novices to get started.
  1. Uses a virtual DOM model to simplify the operation of page elements.
  2. The use of responsive view components helps improve the user experience of the program interface.
  3. The page rendering speed is extremely fast, which can give the application good execution performance.
  4. It can provide routing interfaces for building complex large-scale applications like React.
  5. It can also provide a simple-to-use and well-encapsulated operation interface like jQuery.
Of course, since the author of Vue.js is a Chinese, the Chinese information of the Vue.js community is also richer than that of other JavaScript framework communities. This is for many users who are accustomed to reading in Chinese. This may be the reason for choosing to use this framework.

Introducing the Vue.js framework

Like most JavaScript front-end libraries and application frameworks, there are two main ways to introduce the Vue.js framework into your own project: CDN reference and local reference. Let’s learn about them separately below.

CDN Quote

CDN is the abbreviation of Content Delivery Network or Content Distribution Network, which is a server that uses the existing Internet system closest to the target user. A faster and more reliable way to distribute music, pictures, videos, applications and other data materials, aiming to provide high performance, scalability and low-cost network content delivery to users. In other words, when using the CDN reference method, the Vue.js framework file will be stored on a server node in the designated CDN service network, and the service will be responsible for the access load and maintenance of the framework file. version of the framework, and we only need to reference the URL of the corresponding CDN service in the

<script> tag of the HTML document, like this:

<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 或者 -->
<!-- 生产环境版本,优化了文件大小和载入速度 -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
Copy after login

In the above example, I test To use the CDN service provided by

cdn.jsdelivr.net to reference the Vue.js framework, this is also the service recommended in the Vue.js official tutorial. As for whether to reference the version of the development environment or the version of the production environment, it depends on the specific usage scenario. Under normal circumstances, I would choose to use the development environment version with relatively rich feedback information during the program development stage, and wait until the program is released before switching to the production environment version that pursues more execution efficiency. Let’s take a look at the advantages of using CDN as a reference method:

  • CDN 的总承载量可以比单一骨干最大的带宽还要大。这使得内容分发网络可以承载的用户数量比起传统单一服务器多。
  • CDN 服务器可以被放置到不同地点,这有助于减少计算机之间互连的流量,进而降低带宽成本。
  • CDN 通常会指派较近、较顺畅的服务器节点将资料传输给用户。虽说距离并非影响传输的绝对因素,但这可以尽可能提高性能和用户体验。
  • CDN 上存储的资料通常都会有异地备援,即当某个服务器故障时,系统将会调用其他邻近地区的服务器资料,以提高服务的可靠度。
  • CDN 提供给服务提供者更多的控制权,即提供服务的人可以针对客户、地区,或是其他因素来做相应的调整。

当然了,这种引用方式归根结底都得依赖于网络环境,甚至很多时候是国外的网络环境,由于众所周知的原因,我们的网络环境经常会受到各种不可抗力的影响,所以我个人更倾向于将框架文件下载到本地来引用。

本地引用

正如上面所说,如果想减少意外状况,最好的选择是将 Vue.js 的框架文件下载到本地,然后再引用它们。下载这类文件的方式有很多,现如今为了便于更新版本,人们通常会选择使用 npm 这类包管理器来下载 JavaScript 的各种程序库和应用框架。具体做法就是在之前创建的code目录下执行以下命令:

npm install vue --save
# 如果需要相应的权限,可以使用 sudo 命令来提权
Copy after login

如果安装过程一切顺利,接下来就只需要在 HTML 文档的<script>标签中引用框架文件的路径即可,像这样:

<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="node_modules/vue/dist/vue.js"></script>
<!-- 或者 -->
<!-- 生产环境版本,优化了文件大小和载入速度 -->
<script src="node_modules/vue/dist/vue.min.js"></script>
Copy after login

在这里,选择开发环境版本还是生产环境版本的依据是一样的,就不再重复了。下面来验证一下框架文件是否被成功引入。

程序验证

我将通过编写一个"Hello World"程序来验证 Vue.js 框架是否已被成功引入,具体步骤如下:

  1. code目录下创建一个名为01_sayHello的项目目录,并在该目录下设置以下两个子目录:

    • img目录:用于存放图片资源。
    • js目录:用于存放自定义 JavaScript 脚本文件。
  2. 将名为logo.png的图表文件存储到code/01_sayHello/img目录中。

  3. code/01_sayHello目录中创建一个名为index.htm的 HTML 文档,并在其中输入如下代码:

    <!DOCTYPE html>
    <html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <script defer="defer" src="../node_modules/vue/dist/vue.js"></script>
        <script defer="defer" src="js/main.js"></script>
        <title>你好,Vue.js</title>
    </head>
    <body>
       <p id="app">
          <h1> {{ sayHello }} </h1>
          <img :src="vueLogo" style="width:200px">
       </p>
    </body>
    </html>
    Copy after login
  4. code/01_sayHello/js目录中创建一个名为main.js的 JavaScript 脚本文档,并在其中输入如下代码:

    // 程序名称: sayHello
    // 实现目标:
    //   1. 验证 Vue.js 执行环境
    //   2. 体验构建 Vue.js 程序的基本步骤
    
    const app = new Vue({
       el: &#39;#app&#39;,
       data:{
         sayHello: &#39;你好,Vue.js!&#39;,
         vueLogo: &#39;img/logo.png&#39;
       }
    });
    Copy after login

    接下来只需将相关的 Web 服务运行起来(该服务器可以是 Apache 或者 Nginx,也可以是 VSCode 的 Live Sever 插件),然后如果在 Web 浏览器中看到如下页面,就说明 Vue.js 框架已经被引入到了程序中,并被成功执行起来了。

    更多相关免费学习推荐:js视频教程

    The above is the detailed content of Vue.js learning record one: learning planning and understanding Vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

In-depth discussion of how vite parses .env files In-depth discussion of how vite parses .env files Jan 24, 2023 am 05:30 AM

When using the Vue framework to develop front-end projects, we will deploy multiple environments when deploying. Often the interface domain names called by development, testing and online environments are different. How can we make the distinction? That is using environment variables and patterns.

Detailed graphic explanation of how to integrate the Ace code editor in a Vue project Detailed graphic explanation of how to integrate the Ace code editor in a Vue project Apr 24, 2023 am 10:52 AM

Ace is an embeddable code editor written in JavaScript. It matches the functionality and performance of native editors like Sublime, Vim, and TextMate. It can be easily embedded into any web page and JavaScript application. Ace is maintained as the main editor for the Cloud9 IDE and is the successor to the Mozilla Skywriter (Bespin) project.

What is the difference between componentization and modularization in vue What is the difference between componentization and modularization in vue Dec 15, 2022 pm 12:54 PM

The difference between componentization and modularization: Modularization is divided from the perspective of code logic; it facilitates code layered development and ensures that the functions of each functional module are consistent. Componentization is planning from the perspective of UI interface; componentization of the front end facilitates the reuse of UI components.

Explore how to write unit tests in Vue3 Explore how to write unit tests in Vue3 Apr 25, 2023 pm 07:41 PM

Vue.js has become a very popular framework in front-end development today. As Vue.js continues to evolve, unit testing is becoming more and more important. Today we’ll explore how to write unit tests in Vue.js 3 and provide some best practices and common problems and solutions.

Let's talk in depth about reactive() in vue3 Let's talk in depth about reactive() in vue3 Jan 06, 2023 pm 09:21 PM

Foreword: In the development of vue3, reactive provides a method to implement responsive data. This is a frequently used API in daily development. In this article, the author will explore its internal operating mechanism.

A simple comparison of JSX syntax and template syntax in Vue (analysis of advantages and disadvantages) A simple comparison of JSX syntax and template syntax in Vue (analysis of advantages and disadvantages) Mar 23, 2023 pm 07:53 PM

In Vue.js, developers can use two different syntaxes to create user interfaces: JSX syntax and template syntax. Both syntaxes have their own advantages and disadvantages. Let’s discuss their differences, advantages and disadvantages.

How to query the current vue version How to query the current vue version Dec 19, 2022 pm 04:55 PM

There are two ways to query the current Vue version: 1. In the cmd console, execute the "npm list vue" command to query the version. The output result is the version number information of Vue; 2. Find and open the package.json file in the project and search You can see the version information of vue in the "dependencies" item.

A brief analysis of how to handle exceptions in Vue3 dynamic components A brief analysis of how to handle exceptions in Vue3 dynamic components Dec 02, 2022 pm 09:11 PM

How to handle exceptions in Vue3 dynamic components? The following article will talk about Vue3 dynamic component exception handling methods. I hope it will be helpful to everyone!

See all articles