国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Vue.js之生命周期

HitenDev / 3662人閱讀

摘要:生命周期在實(shí)例初始化之后,數(shù)據(jù)觀測(cè)和事件配置之前被調(diào)用。點(diǎn)擊修改數(shù)據(jù)在中使用組件與在中使用組件是一樣的效果在實(shí)例創(chuàng)建完成后被立即調(diào)用。

有時(shí)候,我們需要在實(shí)例創(chuàng)建過(guò)程中進(jìn)行一些初始化的工作,以幫助我們完成項(xiàng)目中更復(fù)雜更豐富的需求開(kāi)發(fā),針對(duì)這樣的需求,Vue提供給我們一系列的鉤子函數(shù)。

vue生命周期

beforeCreate

在實(shí)例初始化之后,數(shù)據(jù)觀測(cè) (data observer) 和 event/watcher 事件配置之前被調(diào)用。

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="../statics/vue.js">script>
head>
<body>

    <div id="app">
        {{ name }}
        <button @click="myClick">點(diǎn)擊修改數(shù)據(jù)button>
    div>

    <script>

        new Vue({
            el: "#app",
            // 在template中使用組件與在body中使用組件是一樣的
            // template: ``,
            data: {
                name: "Alex"
            },
            methods: {
                init: function () {
                    console.log(this.name);
                },
                myClick: function () {
                    this.name = "Pizza";
                }
            },
            beforeCreate() {
                console.group("beforeCreate");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            });
    script>

body>
html>

效果:

created

在實(shí)例創(chuàng)建完成后被立即調(diào)用。在這一步,實(shí)例已完成以下的配置:數(shù)據(jù)觀測(cè) (data observer),屬性和方法的運(yùn)算,watch/event 事件回調(diào)。然而,掛載階段還沒(méi)開(kāi)始,$el?屬性目前不可見(jiàn)。

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="static/vue.min.js">script>
head>
<body>

    <div id="app">
        {{ name }}
        <button @click="myClick">點(diǎn)擊修改數(shù)據(jù)button>
    div>

    <script>

        new Vue({
            el: "#app",
            // 在template中使用組件與在body中使用組件是一樣的
            // template: ``,
            data: {
                name: "Alex"
            },
            methods: {
                init: function () {
                    console.log(this.name);
                },
                myClick: function () {
                    this.name = "Pizza";
                }
            },
            beforeCreate() {
                console.group("beforeCreate");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            created() {
                console.group("Created");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            }
        })
    script>

body>
html>

beforeMount

在掛載開(kāi)始之前被調(diào)用:相關(guān)的?render?函數(shù)首次被調(diào)用。

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="../statics/vue.js">script>
head>
<body>

    <div id="app">
        {{ name }}
        <button @click="myClick">點(diǎn)擊修改數(shù)據(jù)button>
    div>

    <script>

        new Vue({
            el: "#app",
            // 在template中使用組件與在body中使用組件是一樣的
            // template: ``,
            data: {
                name: "Alex"
            },
            methods: {
                init: function () {
                    console.log(this.name);
                },
                myClick: function () {
                    this.name = "Pizza";
                }
            },
            beforeCreate() {
                console.group("beforeCreate");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            created() {
                console.group("Created");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            beforeMount() {
                console.group("beforeMount");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            }
        })
    script>

body>
html>

mounted

el?被新創(chuàng)建的?vm.$el?替換,并掛載到實(shí)例上去之后調(diào)用該鉤子。如果 root 實(shí)例掛載了一個(gè)文檔內(nèi)元素,當(dāng)?mounted?被調(diào)用時(shí)?vm.$el?也在文檔內(nèi)。

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="../statics/vue.js">script>
head>
<body>

    <div id="app">
        {{ name }}
        <button @click="myClick">點(diǎn)擊修改數(shù)據(jù)button>
    div>

    <script>

        new Vue({
            el: "#app",
            // 在template中使用組件與在body中使用組件是一樣的
            // template: ``,
            data: {
                name: "Alex"
            },
            methods: {
                init: function () {
                    console.log(this.name);
                },
                myClick: function () {
                    this.name = "Pizza";
                }
            },
            beforeCreate() {
                console.group("beforeCreate");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            created() {
                console.group("Created");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            beforeMount() {
                console.group("beforeMount");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            mounted() {
                console.group("mounted");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
        })
    script>

body>
html>

beforeUpdate

數(shù)據(jù)更新時(shí)調(diào)用,發(fā)生在虛擬 DOM 打補(bǔ)丁之前。這里適合在更新之前訪問(wèn)現(xiàn)有的 DOM,比如手動(dòng)移除已添加的事件監(jiān)聽(tīng)器。

該鉤子在服務(wù)器端渲染期間不被調(diào)用,因?yàn)橹挥谐醮武秩緯?huì)在服務(wù)端進(jìn)行.

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="../statics/vue.js">script>
head>
<body>

    <div id="app">
        {{ name }}
        <button @click="myClick">點(diǎn)擊修改數(shù)據(jù)button>
    div>

    <script>

        new Vue({
            el: "#app",
            // 在template中使用組件與在body中使用組件是一樣的
            // template: ``,
            data: {
                name: "Alex"
            },
            methods: {
                init: function () {
                    console.log(this.name);
                },
                myClick: function () {
                    this.name = "Pizza";
                }
            },
            beforeCreate() {
                console.group("beforeCreate");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            created() {
                console.group("Created");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            beforeMount() {
                console.group("beforeMount");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            mounted() {
                console.group("mounted");
                console.log("el: ", this.$el);
                console.log("data: ", this.$data);
                console.log("name: ", this.name);
                console.log("init: ", this.init);
                console.log("innerHTML: ", document.getElementById("app").innerHTML);
            },
            beforeUpdate() {
                console.group("beforeUpdate");
                console.log("el: ", this.$el);
                console.log("data: ", 
                 
               
              

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/1537.html

相關(guān)文章

  • # vue.js 對(duì)vue.js基礎(chǔ)理解

    摘要:之對(duì)基礎(chǔ)理解構(gòu)造器是一個(gè)構(gòu)造函數(shù),編程中稱之為構(gòu)造器每一個(gè)都是一個(gè)構(gòu)造函數(shù)的實(shí)例,這個(gè)過(guò)程叫做實(shí)例化構(gòu)造函數(shù)需要將其實(shí)例化后才會(huì)啟用構(gòu)造器要求實(shí)例化時(shí)需要傳入一個(gè)選項(xiàng)對(duì)象組件其實(shí)都是被擴(kuò)展的實(shí)例。 vue.js 之 對(duì)vue.js基礎(chǔ)理解 Vue構(gòu)造器 1 . Vue.js是一個(gè)構(gòu)造函數(shù),編程中稱之為構(gòu)造器 2 . 每一個(gè)new Vue() 都是一個(gè)Vue構(gòu)造函數(shù)的實(shí)例,這個(gè)過(guò)程叫...

    Rainie 評(píng)論0 收藏0
  • 關(guān)于Vue2一些值得推薦的文章 -- 五、六月份

    摘要:五六月份推薦集合查看最新的請(qǐng)點(diǎn)擊集前端最近很火的框架資源定時(shí)更新,歡迎一下。蘇幕遮燎沈香宋周邦彥燎沈香,消溽暑。鳥(niǎo)雀呼晴,侵曉窺檐語(yǔ)。葉上初陽(yáng)乾宿雨,水面清圓,一一風(fēng)荷舉。家住吳門,久作長(zhǎng)安旅。五月漁郎相憶否。小楫輕舟,夢(mèng)入芙蓉浦。 五、六月份推薦集合 查看github最新的Vue weekly;請(qǐng)::點(diǎn)擊::集web前端最近很火的vue2框架資源;定時(shí)更新,歡迎 Star 一下。 蘇...

    sutaking 評(píng)論0 收藏0
  • 關(guān)于Vue2一些值得推薦的文章 -- 五、六月份

    摘要:五六月份推薦集合查看最新的請(qǐng)點(diǎn)擊集前端最近很火的框架資源定時(shí)更新,歡迎一下。蘇幕遮燎沈香宋周邦彥燎沈香,消溽暑。鳥(niǎo)雀呼晴,侵曉窺檐語(yǔ)。葉上初陽(yáng)乾宿雨,水面清圓,一一風(fēng)荷舉。家住吳門,久作長(zhǎng)安旅。五月漁郎相憶否。小楫輕舟,夢(mèng)入芙蓉浦。 五、六月份推薦集合 查看github最新的Vue weekly;請(qǐng)::點(diǎn)擊::集web前端最近很火的vue2框架資源;定時(shí)更新,歡迎 Star 一下。 蘇...

    khs1994 評(píng)論0 收藏0
  • Vue 實(shí)例中的生命周期鉤子詳解

    摘要:實(shí)例在文檔中經(jīng)常會(huì)使用這個(gè)變量名表示實(shí)例,在實(shí)例化時(shí),需要傳入一個(gè)選項(xiàng)對(duì)象,它可以包含數(shù)據(jù)模板掛載元素方法生命周期鉤子等選項(xiàng)。通俗說(shuō)就是實(shí)例從創(chuàng)建到銷毀的過(guò)程,就是生命周期。 Vue 實(shí)例中的生命周期鉤子 Vue 框架的入口就是 Vue 實(shí)例,其實(shí)就是框架中的 view model ,它包含頁(yè)面中的業(yè)務(wù)處理邏輯、數(shù)據(jù)模型等,它的生命周期中有多個(gè)事件鉤子,讓我們?cè)诳刂普麄€(gè)Vue實(shí)例的過(guò)程...

    gityuan 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<