created:html加載完成之前,執行。執行順序:父組件-子組件
mounted:html加載完成后執行。執行順序:子組件-父組件
methods:事件方法執行
watch:watch是去監聽一個值的變化,然后執行相對應的函數。
computed:computed是計算屬性,也就是依賴其它的屬性計算所得出最后的值
activated:在vue對象存活的情況下,進入當前存在activated()函數的頁面時,一進入頁面就觸發;可用於初始化頁面數據等
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){} }