Vue installation and use

Vue installation and use

Preface:

Vue (pronounced /vjuː/, similar to view) is a framework for building front-end and back-end separation. It was initially developed by the outstanding domestic player You Yuxi and is currently the "most" popular front-end framework in the world. Using vue to develop web pages is very simple, and the technical ecosystem is complete and the community is active. It is a must-have skill for finding a job in the front-end and back-end!

1. Vue installation

The installation of Vue is generally divided into three ways

Method 1: CDN introduction

<!--Development environment version, including helpful warning commands-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>

<!--Generated version, optimized for size and speed-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
 

Method 2: Direct download and import

Development environment: https://vuejs.org/js/vue.js

Production environment: https://vuejs.org/js/vue.min.js

Method 3: npm installation

It is recommended to use NPM installation when building large applications with Vue . NPM works well with module bundlers like webpack or Browserify . At the same time, Vue also provides supporting tools for developing single-file components.

# Latest stable version$ npm install vue
 

2. Basic use

To use Vue , you first need to create a Vue object and pass the el parameter in this object. The full name of the el parameter is element , which is used to find a root element for vue to render. And we can pass a data parameter, all values ​​in data can be used directly under the root element using {{}} .

The sample code is as follows:

<div id="app">
  {{message}}
</div>
</body>
<script>
    const app = new Vue({
      el: "#app",
      data: {
        message: "Beginner Vue"
      }
    })
</script>

The data in data can only be used under the root element of vue and cannot be recognized and rendered vue in other places.

for example:

<!--Cannot render here-->
<p>{{message}}</p>
</body>
<script>
    const app = new Vue({
      el: "#app",
      data: {
        message: "Beginner Vue"
      }
    })
</script>

You can also add methods to the vue object. This property is specifically used to store your own functions. The functions in methods can also be used in templates, and the functions in methods can access the values ​​in data by simply using this. name, without the need to add this.data. name to access it.

The sample code is as follows:

<div id="app">
    <p>{{greet()}}</p>
</div>
</body>
<script>
    const app = new Vue({
      el: "#app",
      data: {
        message: "Beginner Vue"
      },
      methods: {
        greet: function () {
          return "hello" + this.message
        }
      }
    })
</script>

This is the end of this article about Vue installation and usage. For more relevant Vue installation and usage content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue Basics Introduction: Vuex Installation and Use
  • Detailed explanation of the installation and use of Vue-Router
  • Vue router installation and usage analysis
  • Install Vue cli3 globally and continue to use Vue-cli2.x
  • Vue-resource installation process and usage analysis
  • Detailed tutorial on VUE installation and use
  • Graphic tutorial on installing Vue.js using Taobao mirror cnpm

<<:  Analysis of the principle of centering elements with CSS

>>:  Advantages and disadvantages of conditional comments in IE

Recommend

Using vsftp to build an FTP server under Linux (with parameter description)

introduce This chapter mainly introduces the proc...

JavaScript implements simple calculator function

This article shares the specific code of JavaScri...

Example of cross-database query in MySQL

Preface In MySQL, cross-database queries are main...

Example of compiling LNMP in Docker container

Table of contents 1. Project Description 2. Nginx...

Detailed explanation of Linux zabbix agent deployment and configuration methods

1. Install zabbix-agent on web01 Deploy zabbix wa...

How to choose the format when using binlog in MySQL

Table of contents 1. Three modes of binlog 1.Stat...

Summary of Mysql common benchmark commands

mysqlslap Common parameter description –auto-gene...

Tutorial on installing and configuring remote login to MySQL under Ubuntu

This article shares the MySQL installation and co...

Steps to change mysql character set to UTF8 under Linux system

Table of contents 1. Check the MySQL status in th...

Sample code of uniapp vue and nvue carousel components

The vue part is as follows: <template> <...

MySQL and sqlyog installation tutorial with pictures and text

1. MySQL 1.1 MySQL installation mysql-5.5.27-winx...

Detailed explanation of Angular dynamic components

Table of contents Usage scenarios How to achieve ...

Book page turning effects made with CSS3

Result:Implementation code: html <!-- Please h...

Implementing license plate input function in WeChat applet

Table of contents Preface background Big guess Fi...

Summary of MySQL character sets

Table of contents Character Set Comparison Rules ...