亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Vue的Options用法說明

瀏覽:88日期:2022-12-06 16:29:27

el:掛載點

與$mount有替換關系

new Vue({ el: '#app'});new Vue({}).$mount(’#app’)

注:被你選為掛載點的那個元素,如果在index.html里那個元素里面本來就有內(nèi)容,在渲染時會消失(網(wǎng)速慢可以看到),被這個vue實例的對應內(nèi)容所覆蓋。

data:內(nèi)部數(shù)據(jù)

支持對象和函數(shù),優(yōu)先用函數(shù)

new Vue({ //優(yōu)先使用函數(shù) data() { return { n: 0, } }}).$mount('#app');

注:能寫函數(shù)盡量寫函數(shù),否則有可能有BUG;

methods:方法

事件處理函數(shù)

new Vue({ data (){ return{ n:0 } }, template:` <div class='red'> {{n}} <button @click='add'>+1</button> </div> `, //add必須寫到methods里面 methods:{ add(){ this.n+=1 } }}).$mount(’#app’)

普通函數(shù):methods代替filter

import Vue from 'vue';Vue.config.productionTip = false;new Vue({ data() { return { n: 0, array: [1, 2, 3, 4, 5, 6, 7, 8] }; }, template: ` <div class=red> {{n}} <button @click='add'>+1</button> //事件處理函數(shù) <hr> {{filter()}} //普通函數(shù)(JS的filter直接在視圖里調(diào)用,每一次更新渲染都會調(diào)用一次) </div> `,//主動在模板里面調(diào)用 methods: { add() { this.n += 1; //事件處理函數(shù) }, filter() { return this.array.filter(i => i % 2 === 0); //普通函數(shù) } }}).$mount('#app');

components:方法

使用Vue組件,注意大小寫

(建議用法) 模塊化:

新建一個vue文件Demo.vue,這個vue文件就是一個組件

在main.js中引入這個vue文件

在vue實例的components中聲明這是我要用的組件,并且命名為Demo

這樣在這個Vue實例的template中就可以直接使用這個組件<Demo/>

import Vue from 'vue';import Demo from './Demo.vue'; //引入這個vue文件 ---文件名最好小寫 組件名最好大寫Vue.config.productionTip = false;new Vue({ components: { Demo //在vue實例的components中聲明這是我要用的組件,并且命名為Demo //如果組件名就叫Demo,即Demo:Demo,那就寫Demo --ES6縮寫 //components: {Demo}, }, data() { return { n: 0 }; }, template: ` <div class=red> {{n}} <button @click='add'>+1</button> <Demo/> //這樣在這個Vue實例的template中就可以直接使用這個組件`<Demo/>` </div> `, methods: { add() { this.n += 1; }, }}).$mount('#app');

四個鉤子

created -- 實例出現(xiàn)在內(nèi)存中后觸發(fā)created(){ debugger console.log(’這玩意出現(xiàn)在內(nèi)存中’) },

mounted-- 實例出現(xiàn)在頁面中(掛載了)后觸發(fā)

mounted(){ debugger console.log(’這玩意兒已出現(xiàn)在頁面中’) },

updated -- 實例更新了后觸發(fā)

updated(){ console.log(’更新了’) console.log(this.n) }, //當你+1的時候,能證明他在更新的時候觸發(fā),還可以拿到最新的n

destroyed -- 實例從頁面和內(nèi)存中消亡了后觸發(fā)

props:外部屬性

外部來傳值

message='n'傳入字符串

:message='n'傳入vue實例的this.n數(shù)據(jù)

:fn='add'傳入vue實例的this.add函數(shù)

示例

補充知識:vue $options初始化

vue實例化時,對$options進行初始化

vue/src/core/instance/init.js

Vue.prototype._init = function (options?: Object) { const vm: Component = this // a uid vm._uid = uid++ let startTag, endTag /* istanbul ignore if */ if (process.env.NODE_ENV !== ’production’ && config.performance && mark) { startTag = `vue-perf-start:${vm._uid}` endTag = `vue-perf-end:${vm._uid}` mark(startTag) } // a flag to avoid this being observed vm._isVue = true // merge options if (options && options._isComponent) { // optimize internal component instantiation // since dynamic options merging is pretty slow, and none of the // internal component options needs special treatment. initInternalComponent(vm, options) } else { //初始化$options vm.$options = mergeOptions( resolveConstructorOptions(vm.constructor), options || {}, vm ) } /* istanbul ignore else */ if (process.env.NODE_ENV !== ’production’) { initProxy(vm) } else { vm._renderProxy = vm } }}

以上這篇Vue的Options用法說明就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關文章:
主站蜘蛛池模板: 亚洲精品中文一区不卡 | 国产成年女人免费视频播放a | 国产精品天天影视久久综合网 | 国产亚洲一区二区三区啪 | 久久亚洲国产 | 国产亚洲精品一区二区 | 国产亚洲精品午夜一区 | 午夜黄页网站在线播放 | 国产精品制服诱惑 | 欧美一级毛片免费观看软件 | 香蕉97超级碰碰碰碰碰久 | 日韩欧美视频免费观看 | 视频精品一区 | 加勒比一道本综合 | 日本福利视频一区 | 成年女人天堂香蕉网视频 | 口国产成人高清在线播放 | 欧美中文字幕一区二区三区 | 黄色一级免费片 | 免费毛片大全 | 老年人一级毛片 | 在线观看黄色网 | 亚洲天堂h| 日韩免费一级毛片 | 黄色片欧美 | 欧美成人h精品网站 | 亚洲精品中文一区不卡 | 欧美日韩在线视频不卡一区二区三区 | 日本xxwwwxxxx| 免费一级毛片不卡在线播放 | 色综合久久天天综线观看 | 男女动态视频在线观看 | 久久66热re国产毛片基地 | 欧美成人观看免费版 | 一区二区三区视频观看 | 国产女人一区二区 | 亚洲欧美另类一区 | 天天天天鲁天天拍一拍 | 1000部啪啪未满十八勿入中国 | 欧美精品亚洲精品日韩经典 | 亚洲欧美中文日韩综合 |