search
HomeWeb Front-endFront-end Q&AWhat are the options of vue?
What are the options of vue?Dec 22, 2022 pm 08:14 PM
vue

In vue, the options option refers to the "construction option", which is a parameter passed in when creating a Vue instance. It is an object, and the syntax is "const vm = new Vue(options)". Use "new Vue(options)" to create a Vue instance, also called a Vue object. This Vue instance encapsulates all operations for operating element views. You can easily operate the view of the corresponding area through the Vue instance.

What are the options of vue?

The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.

The role of options in Vue

What are options

options
As the name suggests, it means "options", or construction options. It is a parameter passed in when creating a Vue instance and is an object.
const vm = new Vue(options)

  • Whether it is jquery.js or Vue.js, the corresponding operations are encapsulated again on the basis of js. For example: Get a jQuery div element instance through $('div'), also called a jQuery object. The jQuery object contains various operation APIs for the div elements in the options, so the jQuery instance encapsulates the operations on the elements in the options. Various operations;
  • And Vue.js goes one step further on this basis, encapsulating all operations on the view, including reading and writing data, monitoring data changes, updating DOM elements, etc., through new Vue (options) to create a Vue instance, also called a Vue object. This Vue instance encapsulates all operations for operating element views. You can easily operate the view of the corresponding area through the Vue instance;

Five types of attributes of options

  • ##Data: data, props, propsData, computed, Watch;

  • DOM: el, template, render, renderError;

  • Lifecycle hook: beforeCreate, created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, destroyed, errorCaptured;

  • ##Resources:

    directives, filters, components;

  • Combinations:

    parent, mixins, extends, provide, inject;

##Getting started attributes


el (hanging point)

    new Vue({
        el:"#app"
        template:`<div>我是小明</div>`
    })
    可以使用$mount代替
    new Vue({
        template:`<div>我是小明</div>`
    }).$mount("#app")
  • data (internal data) supports objects and functions, using functions first
    Will be monitored by Vue
    • Will be proxied by the Vue instance
    • Every data read and write will be monitored by Vue
    • Vue will update when the data changes UI
    • 对象
      new Vue({
          template:"<div>{{n}}</div>",
          data:{
              n:0
          }
      }).$mount(&#39;#app&#39;)
      函数
      vue非完整版只支持函数
      new Vue({
          template:"<div>{{n}}</div>",
          data(){
              return {
                  m:5
              }
          }
      })$mount(&#39;#app&#39;)
  • methods (method) event handling function or ordinary function
    new Vue({
        template:"<div>{{n}}{{ add()}} <button @click="add">按钮</button></div>",
        data:{
            n:0
        },
        methods:{
            add(){
        	console.log(&#39;我可以是事件处理函数也可以是普通函数&#39;)
    }
            }
    }).$mount(&#39;#app&#39;)
  • components (vue component: pay attention to the size Write) three ways
    注册全局组件
    Vue.component(&#39;Deon1&#39;, {
      template: "<h2 id="全局组件">全局组件</h2>"
    })
    注册局部组件
    const deon2 = {
      template: "<h2 id="局部组件-nbsp-n">局部组件 {{n}}</h2>",
       //在组建中data必须使用函数
      data() {
        return {
          n: "小明"
        }
      }
    }
    new Vue({
      components: {
        Deon2: deon2,
        Deon3:{
          template:"<h2>组件3</h3>"
      }
      },
      template: `
        <div>页面
        <Deon1></Deon1>
        <Deon2></Deon2>
     	<Deon3></Deon3>
        </div> 
      `
    }).$mount(&#39;#app&#39;)
Add components using vue files

deon4.vue file

<template>
  <div>我是deon.vue文件{{ name }}</div>
</template>
<script>
export default {
  data() {
    name: "组件4";
  },
};
</script>
<style scoped>
div {
  border: 1px solid red;
}
</style>

main .js

import Deon4 from &#39;./deon4.vue&#39;
Vue.component(&#39;Deon1&#39;, {
  template: "<h2 id="全局组件">全局组件</h2>"
})
const deon2 = {
  template: "<h2 id="局部组件-nbsp-n">局部组件 {{n}}</h2>",
  //在组建中data必须使用函数
  data() {
    return {
      n: "小明"
    }
  }
}
new Vue({
  components: {
    Deon2: deon2,
    Deon3: {
      template: "<h2>组件3</h3>"
    },
    Deon4
  },
  template: `
    <div>页面
    <Deon1></Deon1>
    <Deon2></Deon2>
    <Deon3></Deon3>
    <Deon4><Deon4>
    </div> 
  `
}).$mount(&#39;#app&#39;)

Four commonly used life cycle hook functions

    created: The instance appears in the memory
    • mounted: The instance appears in the page and triggers
    • updated: Triggered by changes in the instance
    • destroyed: Triggered by the instance being destroyed
    • new Vue({
          template:"<div>{{n}}</div>",
          data:{
              n:0
          },
           created() {
          console.log("实例出现在内存中了触发");
        },
        mounted() {
          console.log("实例出现在页面中触发");
        },
        updated() {
          console.log("实例出现了变化触发");
        },
        destroyed() {
          console.log("实例被销毁了触发");
        }
      }).$mount(&#39;#app&#39;)
  • props (external data) parent component wants Subgroup passing value
    name="n" (pass in string)
    • :name="n" (pass in this.n data)
    • :fn= "add": (pass in this.add function)
    • new Vue({
        components: {
          Deon1: {
            props: ["m"],
            template: "<div>{{m}}</div>"
          }
        },
        template: `<div><Deon1 :m="m"></Deon1></div>`,
        data: {
          m: 666
        }
      }).$mount(&#39;#app&#39;)
    [Related recommendations:
  • vuejs video tutorial
,

web front-end development

The above is the detailed content of What are the options of 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
Vue常见面试题汇总(附答案解析)Vue常见面试题汇总(附答案解析)Apr 08, 2021 pm 07:54 PM

本篇文章给大家分享一些Vue面试题(附答案解析)。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

5 款适合国内使用的 Vue 移动端 UI 组件库5 款适合国内使用的 Vue 移动端 UI 组件库May 05, 2022 pm 09:11 PM

本篇文章给大家分享5 款适合国内使用的 Vue 移动端 UI 组件库,希望对大家有所帮助!

vue中props可以传递函数吗vue中props可以传递函数吗Jun 16, 2022 am 10:39 AM

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

手把手带你利用vue3.x绘制流程图手把手带你利用vue3.x绘制流程图Jun 08, 2022 am 11:57 AM

利用vue3.x怎么绘制流程图?下面本篇文章给大家分享基于 vue3.x 的流程图绘制方法,希望对大家有所帮助!

聊聊vue指令中的修饰符,常用事件修饰符总结聊聊vue指令中的修饰符,常用事件修饰符总结May 09, 2022 am 11:07 AM

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

如何覆盖组件库样式?React和Vue项目的解决方法浅析如何覆盖组件库样式?React和Vue项目的解决方法浅析May 16, 2022 am 11:15 AM

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

通过9个Vue3 组件库,看看聊前端的流行趋势!通过9个Vue3 组件库,看看聊前端的流行趋势!May 07, 2022 am 11:31 AM

本篇文章给大家分享9个开源的 Vue3 组件库,通过它们聊聊发现的前端的流行趋势,希望对大家有所帮助!

react与vue的虚拟dom有什么区别react与vue的虚拟dom有什么区别Apr 22, 2022 am 11:11 AM

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。

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尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.