Vue生命周期鈎子函數加載順序的理解


Vue實例有一個完整的生命周期,也就是從開始創建、初始化數據、編譯模板、掛載Dom、渲染→更新→渲染、卸載等一系列過程,我們稱這是Vue的生命周期。通俗說就是Vue實例從創建到銷毀的過程,就是生命周期。

created:html加載完成之前,執行。執行順序:父組件-子組件

mounted:html加載完成后執行。執行順序:子組件-父組件

methods:事件方法執行

watch:watch是去監聽一個值的變化,然后執行相對應的函數。

computed:computed是計算屬性,也就是依賴其它的屬性計算所得出最后的值

export default {
     name: "draw",
     data(){      // 定義變量source        
       return {
         source:new ol.source.Vector({wrapX: false}),

       }
     },
    props:{ //接收父組件傳遞過來的參數
      map:{
        //type:String
      },

    },

mounted(){   //頁面初始化方法
    if (map==map){

    }
    var vector = new ol.layer.Vector({
      source: this.source
    });
    this.map.addLayer(vector);

  },
  watch: {   //監聽值變化:map值
    map:function () {
      console.log('3333'+this.map);
      //return this.map
      console.log('444444'+this.map);

      var vector = new ol.layer.Vector({
        source: this.source
      });
      this.map.addLayer(vector);
    }
  },
  methods:{   //監聽方法  click事件等,執行drawFeatures方法
       drawFeatures:function(drawType){}
}

 

vue中created、mounted等方法整理  https://blog.csdn.net/liudoris/article/details/80255311

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM