vue中created、mounted等方法整理

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){}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值