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.
The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.
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)
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;
directives, filters, components;
parent, mixins, extends, provide, inject;
el (hanging point)
new Vue({ el:"#app" template:`<div>我是小明</div>` }) 可以使用$mount代替 new Vue({ template:`<div>我是小明</div>` }).$mount("#app")
对象 new Vue({ template:"<div>{{n}}</div>", data:{ n:0 } }).$mount('#app') 函数 vue非完整版只支持函数 new Vue({ template:"<div>{{n}}</div>", data(){ return { m:5 } } })$mount('#app')
new Vue({ template:"<div>{{n}}{{ add()}} <button @click="add">按钮</button></div>", data:{ n:0 }, methods:{ add(){ console.log('我可以是事件处理函数也可以是普通函数') } } }).$mount('#app')
注册全局组件 Vue.component('Deon1', { template: "<h2>全局组件</h2>" }) 注册局部组件 const deon2 = { template: "<h2>局部组件 {{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('#app')
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>
import Deon4 from './deon4.vue' Vue.component('Deon1', { template: "<h2>全局组件</h2>" }) const deon2 = { template: "<h2>局部组件 {{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('#app')
Four commonly used life cycle hook functions
new Vue({ template:"<div>{{n}}</div>", data:{ n:0 }, created() { console.log("实例出现在内存中了触发"); }, mounted() { console.log("实例出现在页面中触发"); }, updated() { console.log("实例出现了变化触发"); }, destroyed() { console.log("实例被销毁了触发"); } }).$mount('#app')
new Vue({ components: { Deon1: { props: ["m"], template: "<div>{{m}}</div>" } }, template: `<div><Deon1 :m="m"></Deon1></div>`, data: { m: 666 } }).$mount('#app')
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!