search
HomeWeb Front-endVue.jsBasic tutorial on Vue without losing money (with detailed explanations with examples)

This article has compiled a detailed basic learning knowledge of Vue, which includes the basic introduction of vue and the basic use of vue. It also brings some detailed explanations of basic examples. I hope it will be helpful to everyone!

Basic tutorial on Vue without losing money (with detailed explanations with examples)

1. Basic introduction to Vue

1. What is Vue.js

  • Vue.js is currently the most popular A front-end framework, React is the most popular front-end framework (in addition to developing websites, React can also develop mobile apps, and Vue syntax can also be used for mobile app development, requiring the help of Weex)
  • Vue.js is one of the mainstream frameworks of the front-end. Together with Angular.js and React.js, it has become the three mainstream frameworks of the front-end!
  • Vue.js is a framework for building user interfaces, only focuses on the view layer. It is not only easy to get started, but also easy to integrate with third-party libraries or existing projects. (Vue has supporting third-party class libraries that can be integrated for the development of large-scale projects)
  • The main work of the front-end? Mainly responsible for the V layer in MVC; the main job is to deal with the interface to create the front-end page effect;
  • For enterprises Improve development efficiency: In enterprises, time is efficiency, and efficiency is money;
  • In enterprises, the use of frameworks can improve development efficiency;
  • The development process of improving development efficiency: native JS - > Class libraries such as Jquery -> Front-end template engine -> Angular.js / Vue.js (can help us reduce unnecessary DOM operations; improve rendering efficiency; the concept of two-way data binding [provided by the framework Instructions, our front-end programmers only need to care about the business logic of the data and no longer care about how the DOM is rendered])
  • In Vue, a core concept is to allow users to no longer operate DOM elements and liberate Freeing the user's hands, allowing programmers to spend more time focusing on business logic;

3. The difference between MVC in Node (backend) and MVVM in the frontend

  • MVC is the concept of layered development of the back-end;
  • MVVM is the concept of the front-end view layer, which mainly focuses on the separation of the view layer. That is to say: MVVM divides the front-end view layer into three parts Model, View, VM ViewModel
  • Why do we need MVVM when we have MVC

Basic tutorial on Vue without losing money (with detailed explanations with examples)

MVVM is a layered development of the front-end view layer The idea is to divide each page into M, V and VM. VM is the core idea of ​​MVVM: because VM connects M and V.
The idea of ​​using MVVM in the front-end page is mainly to allow us to develop MVVM to provide two-way binding of data. The two-way binding is provided by VM

II 、Basic use of Vue

 This time the coding tool is Visual Studio Code, friends can download and install it by themselves.

1. The first case

The code is as follows:

nbsp;html>
  <meta>
  <meta>
  <meta>
  <title>Document</title>
  <!-- 1. 导入Vue的包 -->
  <script></script>
  <!-- 将来 new 的Vue实例,会控制这个 元素中的所有内容 -->
  <!-- 3. Vue 实例所控制的这个元素区域,就是我们的 V  -->
  <p>
    </p><p>{{ msg }}</p>
  

  <script>
    // 2. 创建一个Vue的实例
    // 当我们导入包之后,在浏览器的内存中,就多了一个 Vue 构造函数
    //  注意:我们 new 出来的这个 vm 对象,就是我们 MVVM中的 VM调度者
    var vm = new Vue({
      el: &#39;#app&#39;,  // 表示,当前我们 new 的这个 Vue 实例,要控制页面上的哪个区域
      // 这里的 data 就是 MVVM中的 M,专门用来保存 每个页面的数据的
      data: { // data 属性中,存放的是 el 中要用到的数据
      msg: &#39;欢迎学习Vue&#39; // 通过 Vue 提供的指令,很方便的就能把数据渲染到页面上,程序员不再手动操作DOM元素了【前端的Vue之类的框架,不提倡我们去手动操作DOM元素了】
      }
    })
  </script>

Pay attention to the comments in the code!

Visit the page

Basic tutorial on Vue without losing money (with detailed explanations with examples)

Basic tutorial on Vue without losing money (with detailed explanations with examples)

2. Common commands

##{Interpolation expressionv-cloakSolve the problem of flickering of interpolation expressionsv-textThe same as interpolation, it is also used in vue Variables, but there is no flashing problem by default, but the original content will be overwritten, and the interpolation will not v-htmldisplay the HTML contentv-bindThe attribute binding mechanism provided by Vue, the abbreviation is ':'v-onVue The event binding mechanism provided, the abbreviation is: '@'

2.1 插值表达式

  在HTML页面中我们需要获取Vue中的数据,这时我们可以通过插值表达式来获取,如下

  <p>
  	<!-- 插值表达式获取vue中的msg信息 -->
    </p><p>{{ msg }}</p>
  

  <script>
    var vm = new Vue({
      el: &#39;#app&#39;, 
      data: {
        msg: &#39;欢迎学习Vue&#39; 
      }
    })</script>

注意:插值表达式有闪缩的问题
我们以站点的方式启动,Ctrl+shift+p :在输入中搜索 如下

Basic tutorial on Vue without losing money (with detailed explanations with examples)

Basic tutorial on Vue without losing money (with detailed explanations with examples)

访问地址:http://localhost/xxx.html

Basic tutorial on Vue without losing money (with detailed explanations with examples)

Basic tutorial on Vue without losing money (with detailed explanations with examples)

加载完成就会变好!这就是插值闪烁的问题

2.2 v-cloak

  v-cloak指令可以解决上面插值闪烁的问题,如下:其实利用的就是当插值没有被加载出来的是通过 style属性将内容给隐藏了。

nbsp;html>
  <meta>
  <meta>
  <meta>
  <title>Document</title>
  <style>
    [v-cloak] {
       display: none; 
    }
  </style>
  <p>
    <!-- 使用 v-cloak 能够解决 插值表达式闪烁的问题 -->
    </p><p>++++++++ {{ msg }} ----------</p>
  
  <script></script>

  <script>
    var vm = new Vue({
      el: &#39;#app&#39;,
      data: {
        msg: &#39;hello&#39;,
      }
    })
  </script>

2.3 v-text

  和插值差不多,也可以从vue对象中获取信息,v-text默认是没有闪烁问题的,但是会覆盖掉原有的内容,但是 插值表达式 只会替换自己的这个占位符,不会把 整个元素的内容清空,如下

nbsp;html>
    <meta>
    <meta>
    <meta>
    <title>Document</title>
    <script></script>
    <p>
        </p><p>----{{msg}}=====</p>
        <p></p>
        <p>*******</p>
    
    <script>
        var vm = new Vue({
            el:"#app",
            data:{
                msg:"hello vue"
            }
        })
    </script>

Basic tutorial on Vue without losing money (with detailed explanations with examples)

2.4 v-html

  默认我们从Vue对象中获取的信息如果含有HTML标签的话只会当做普通字符串显示,如果我们要显示标签的语义,那么需要使用v-html指令如下

nbsp;html>
    <meta>
    <meta>
    <meta>
    <title>Document</title>
    <script></script>
    <p>
        </p><p>----{{msg}}=====</p>
        <p></p>
        <p>*******</p>
        <p></p>
    
    <script>
        var vm = new Vue({
            el:"#app",
            data:{
                msg:"<h3>hello vue"
            }
        })
    </script>

Basic tutorial on Vue without losing money (with detailed explanations with examples)

2.5 v-bind

  v-bind是 Vue中,提供的用于绑定属性的指令,可简写为":",属性中的内容其实写的是js表达式,可以做类似的处理,见代码。

nbsp;html>
    <meta>
    <meta>
    <meta>
    <title>Document</title>
    <script></script>
    <p>
        <input><br>
        <input>
        <!-- 注意: v-bind: 指令可以被简写为 :要绑定的属性 -->
        <input>
        <!-- v-bind 中,可以写合法的JS表达式-->
       <input>
    </p>
    <script>
        var vm = new Vue({
            el:"#app",
            data:{
                title:"title123"
            }
        })
    </script>

Basic tutorial on Vue without losing money (with detailed explanations with examples)

2.6 v-on

  Vue 中提供了 v-on: 事件绑定机制,具体使用如下:

nbsp;html>
    <meta>
    <meta>
    <meta>
    <title>Document</title>
    <script></script>
    <p>
        <input>
        <!--还可以缩写为 @-->
        <input>
    </p>
    <script>
        var vm = new Vue({
            el:"#app",
            data:{
                msg:"<h3>hello vue"
            },
            methods:{
                show:function(){
                    alert(&#39;hello&#39;)
                }
            }
        })
    </script>

Basic tutorial on Vue without losing money (with detailed explanations with examples)

更多编程相关知识,请访问:编程入门!!

Instruction Description
{}}

The above is the detailed content of Basic tutorial on Vue without losing money (with detailed explanations with examples). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
The Choice of Frameworks: What Drives Netflix's Decisions?The Choice of Frameworks: What Drives Netflix's Decisions?Apr 13, 2025 am 12:05 AM

Netflix mainly considers performance, scalability, development efficiency, ecosystem, technical debt and maintenance costs in framework selection. 1. Performance and scalability: Java and SpringBoot are selected to efficiently process massive data and high concurrent requests. 2. Development efficiency and ecosystem: Use React to improve front-end development efficiency and utilize its rich ecosystem. 3. Technical debt and maintenance costs: Choose Node.js to build microservices to reduce maintenance costs and technical debt.

React, Vue, and the Future of Netflix's FrontendReact, Vue, and the Future of Netflix's FrontendApr 12, 2025 am 12:12 AM

Netflix mainly uses React as the front-end framework, supplemented by Vue for specific functions. 1) React's componentization and virtual DOM improve the performance and development efficiency of Netflix applications. 2) Vue is used in Netflix's internal tools and small projects, and its flexibility and ease of use are key.

Vue.js in the Frontend: Real-World Applications and ExamplesVue.js in the Frontend: Real-World Applications and ExamplesApr 11, 2025 am 12:12 AM

Vue.js is a progressive JavaScript framework suitable for building complex user interfaces. 1) Its core concepts include responsive data, componentization and virtual DOM. 2) In practical applications, it can be demonstrated by building Todo applications and integrating VueRouter. 3) When debugging, it is recommended to use VueDevtools and console.log. 4) Performance optimization can be achieved through v-if/v-show, list rendering optimization, asynchronous loading of components, etc.

Vue.js and React: Understanding the Key DifferencesVue.js and React: Understanding the Key DifferencesApr 10, 2025 am 09:26 AM

Vue.js is suitable for small to medium-sized projects, while React is more suitable for large and complex applications. 1. Vue.js' responsive system automatically updates the DOM through dependency tracking, making it easy to manage data changes. 2.React adopts a one-way data flow, and data flows from the parent component to the child component, providing a clear data flow and an easy-to-debug structure.

Vue.js vs. React: Project-Specific ConsiderationsVue.js vs. React: Project-Specific ConsiderationsApr 09, 2025 am 12:01 AM

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

How to jump a tag to vueHow to jump a tag to vueApr 08, 2025 am 09:24 AM

The methods to implement the jump of a tag in Vue include: using the a tag in the HTML template to specify the href attribute. Use the router-link component of Vue routing. Use this.$router.push() method in JavaScript. Parameters can be passed through the query parameter and routes are configured in the router options for dynamic jumps.

How to implement component jump for vueHow to implement component jump for vueApr 08, 2025 am 09:21 AM

There are the following methods to implement component jump in Vue: use router-link and <router-view> components to perform hyperlink jump, and specify the :to attribute as the target path. Use the <router-view> component directly to display the currently routed rendered components. Use the router.push() and router.replace() methods for programmatic navigation. The former saves history and the latter replaces the current route without leaving records.

How to jump to the div of vueHow to jump to the div of vueApr 08, 2025 am 09:18 AM

There are two ways to jump div elements in Vue: use Vue Router and add router-link component. Add the @click event listener and call this.$router.push() method to jump.

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools