created:html加载完成之前,执行。执行顺序:父组件-子组件
mounted:html加载完成后执行。执行顺序:子组件-父组件
methods:事件方法执行
watch:watch是去监听一个值的变化,然后执行相对应的函数。
computed:computed是计算属性,也就是依赖其它的属性计算所得出最后的值
export default { name: "draw", data(){ // 定义变量source return { source:new ol.source.Vector({wrapX: false}),} }, <span style="color:rgb(102,14,122);"><strong>props</strong></span>:{ <em><span style="color:#ff6666;">//接收父组件传递过来的参数</span></em><span style="color:rgb(128,128,128);"><em>
map:{
//type:String
},
},
mounted(){ //页面初始化方法
if (map==map){
}
<span style="color:rgb(0,0,128);"><strong>var </strong></span><span style="color:rgb(69,131,131);">vector </span>= <span style="color:rgb(0,0,128);"><strong>new </strong></span>ol.layer.Vector({
<span style="color:rgb(102,14,122);"><strong>source</strong></span>: <span style="color:rgb(0,0,128);"><strong>this</strong></span>.<span style="color:rgb(102,14,122);"><strong>source
});
this.map.addLayer(vector);
},
watch: { //监听值变化:map值
map:function () {
console.log(‘3333’+this.map);
//return this.map
console.log(‘444444’+this.map);
<span style="color:rgb(0,0,128);"><strong>var </strong></span><span style="color:rgb(69,131,131);">vector </span>= <span style="color:rgb(0,0,128);"><strong>new </strong></span>ol.layer.Vector({
<span style="color:rgb(102,14,122);"><strong>source</strong></span>: <span style="color:rgb(0,0,128);"><strong>this</strong></span>.<span style="color:rgb(102,14,122);"><strong>source
});
this.map.addLayer(vector);
}
},
methods:{ //监听方法 click事件等,执行drawFeatures方法
drawFeatures:function(drawType){}
}