search
HomeWeb Front-endJS TutorialBasic knowledge for newbies to vue
Basic knowledge for newbies to vueMay 02, 2018 pm 02:48 PM
basic knowledgeBeginner's guide

This time I will bring you the basic knowledge of what novices of Vue need to know about getting started. What are the precautions that novices of Vue need to know. Here are practical cases. Let’s take a look.

1. What is vue

Vue is a progressive framework for building user interfaces.

Only 17kb after compression

2. Vue environment construction

You download it directly and import it with the <script> tag , Vue will be registered as a global variable. </script>

But it is recommended to use NPM installation when building large applications with Vue.

The recommendation here is to use Taobao's cnpm, which is very fast

npm install -g cnpm --registry=https://registry.npm.taobao.org

Then install it

# 全局安装 vue-cli
 npm install --g vue-cli
# 创建一个基于 webpack 模板的新项目
 vue init webpack my-project
# 安装依赖,走你
 cd my-project
 npm run dev

3. The first vue application

nbsp;html>


 <meta>
 <title></title>


 <p>
  </p><p>{{title}}</p>
  <button>单击事件</button>
  <p>今年{{age}}</p>
  <input>
 


<script></script>
<script></script>
var app = new Vue({  //通过构造函数Vue就可以创建一个Vue的根实例,并启动Vue应用
 el: '#app', //指定页面上一个已经存在的DOM元素来挂载Vue实例
 data: {  //对象的数据
  title: 'hello vue', //通过插值语法{{}}绑定
  age: 22  //通过v-model进行双向数据绑定
 },
 methods: { //对象的方法
  say: function(){
   console.log(this.title);
  }
 },
 watch: { //监听数据的变化
  'age': function(newVal, oldVal){
   console.log(newVal, oldVal);
  }
 }
});

4. VueLife cycle

When each Vue instance is created, it will go through a series of initialization processes and also call corresponding life cycle hooks. We can use these hooks to execute our business logic at the appropriate time.

The general life cycle is: created---mounted---destroy

The more commonly used life cycle hooks of Vue are:

• created is called after the instance is created. At this stage, data observation, etc. are completed, but it has not been mounted yet, and $el is not available yet. It will be more useful when you need to initialize and process some data.

• mounted el is called after mounting to the instance. Generally, our first business logic will start here.

• beforeDestroy is called before the instance is destroyed. Mainly unbind some events monitored using addEventListener.

var app =new Vue({
 el: '# app',
 data: {
  a: 2
 } ,
 created: function () {
  console.log(this.a); //2
 },
 mounted: function () {
  console.log(this.el); //<p></p>
 }
});

A complete life cycle diagram:

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the PHP Chinese website article!

Recommended reading:

vue built-in instruction instructions

How FileReader implements a file reader

The above is the detailed content of Basic knowledge for newbies to vue. 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
从零开始学习如何玩转海绵宝宝大闹蟹堡王从零开始学习如何玩转海绵宝宝大闹蟹堡王Jan 26, 2024 pm 02:15 PM

《海绵宝宝大闹蟹堡王》是一款烹饪模拟经营游戏,玩法快节奏且充满惊喜料理。你将扮演海绵宝宝,在游戏中拓展各类餐厅和厨房,带来欢乐。对于新手玩家,以下是一些攻略建议:首先,合理安排厨房布局,提高工作效率;其次,注意食材的采购和存储,确保供应充足;还要关注顾客的需求,及时处理订单;最后,不断升级设备和菜谱,吸引更多顾客。通过这些技巧,你将能够在游戏中获得更好海绵宝宝大闹蟹堡王新手入门教程1、在开局都有一个小目标,玩家只需完成目标,即可通关;2、在制作的过程中,大家一定要仔细查看客人的需求;3、每完成一

奶牛镇游戏的新手指南和攻略奶牛镇游戏的新手指南和攻略Jan 23, 2024 pm 09:06 PM

奶牛镇的小时光是一款备受玩家喜爱的休闲经营种田游戏。游戏设定了悠闲的节奏和轻松的玩法,让玩家可以在模拟乡镇的世界中打造属于自己的趣味故事。很多新手玩家对这种独特的经营模拟游戏都很感兴趣。在这里,我将为大家分享一些适合新手的入门玩法攻略,帮助他们更好地开始游戏。奶牛镇的小时光新手入门玩法攻略奶牛镇的小时光是一款开放式模拟乡镇生活手游,在这个像素小天地中,你将体验到开荒种地,畜牧养殖,搭建庄园工坊,攻略小镇居民等全新农场生活,更有钓鱼赛马,开矿探险,赶集贸易等多样玩法,等待你体验这个全新的奶牛镇。大

学习MySQL必看!详细讲解SQL语句基础知识学习MySQL必看!详细讲解SQL语句基础知识Jun 15, 2023 pm 09:00 PM

MySQL是一个开源的关系型数据库管理系统,被广泛地应用于Web应用程序的开发和数据存储。学习MySQL的SQL语言对于数据管理员和开发者来说是非常必要的。SQL语言是MySQL中的核心部分,因此在学习MySQL之前,你需要对SQL语言有充分的了解,本文旨在为你详细讲解SQL语句基础知识,让你一步步了解SQL语句。SQL是结构化查询语言的简称,用于在关系型数

从头学习:掌握Go语言的基础知识从头学习:掌握Go语言的基础知识Feb 01, 2024 am 08:45 AM

从零开始:学习Go语言的基础知识简介Go语言,又称Golang,是一种由Google开发的开源编程语言。它于2009年发布,并迅速成为一种流行的语言,尤其是在Web开发、分布式系统和云计算等领域。Go语言以其简洁、高效、并发性强等特点而著称。基本语法1.变量和常量在Go语言中,变量和常量都是类型化的。变量可以存储数据,而常量则不能改变。变量的声明格式为:v

学习canvas,需要了解哪些基本概念?学习canvas,需要了解哪些基本概念?Jan 17, 2024 am 10:37 AM

学习canvas需要掌握哪些基础知识?随着现代Web技术的发展,使用HTML5中的标签进行绘图成为一种常见的方式。Canvas是一种用于绘制图形、动画和其他图像的HTML元素,它可以利用JavaScript进行操作和控制。如果你想要学习canvas并掌握其基础知识,下面将为你详细介绍。HTML和CSS基础知识:在学习canvas之

Go语言编程入门指南:基础知识与实际应用速成Go语言编程入门指南:基础知识与实际应用速成Jan 23, 2024 am 09:31 AM

快速入门Go语言编程:基础知识与实践指南Go语言作为一门新兴的编程语言,因其简洁、高效和并发性而备受开发者的青睐。无论你是初学者还是有一定编程经验的开发者,本文将带你快速入门Go语言编程,并提供一些实践指南和具体代码示例。一、安装Go语言环境要开始使用Go语言进行编程,首先需要在你的计算机上安装Go语言环境。你可以从Go官方网站(https://golang

Yii框架的一些基础知识Yii框架的一些基础知识Jun 21, 2023 pm 07:07 PM

Yii是一款流行的面向对象PHP框架,它的全称是“YesItIs”,表示“是的,它就是这样的”。它的设计目标是高效、快速、安全和易于使用,因此被广泛应用于大型Web应用程序的开发中。在这篇文章中,我们将介绍Yii框架的一些基础知识,帮助新手更好地了解这个框架。MVC架构Yii框架采用了基于MVC(Model-View-Controller)的设计模式,这

深入探讨Go语言程序的基础知识深入探讨Go语言程序的基础知识Mar 05, 2024 am 08:15 AM

《Go语言程序基础知识深入探讨:具体代码示例解析》Go语言作为一种快速、高效的编程语言,越来越受到程序员和开发者的青睐。在学习和掌握Go语言的过程中,深入了解其基础知识是至关重要的。本文将从变量、数据类型、流程控制以及函数等方面展开深入探讨,同时结合具体的代码示例来帮助读者更好地理解和掌握Go语言的基础知识。变量和数据类型在Go语言中,变量的声明和初始化非常

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

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),

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

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.