created:html加载完成之前,执行。执行顺序:父组件-子组件created:mounted:html加载完成后执行。执行顺序:子组件-父组件mounted:methods:事件方法执行methods:watch:watch是去监听一个值的变化,然后执行相对应的函数。watch:computed: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){}
}

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中在mounted中window.onresize不生效补充知识:补充知识:vue中在mounted中window.onresize不生效在vue开发中,因为引用的父组件和子组件都使用了window.onresize以至于一个window.onresize失效。解决方案==>可以采用下面的方式解决方案==>可以采用下面的方式
window.onresize = () => this.screenWidth = window.innerWidth
// 改为以下写法
window.addEventListener('resize', () => this.screenWidth = window.innerWidth, false)
window.onresize = () => this.screenWidth = window.innerWidth
// 改为以下写法
window.addEventListener('resize', () => this.screenWidth = window.innerWidth, false)以上这篇在vue中created、mounted等方法使用小结就是小编分享给大家的全部内容了,希望能给大家一个参考。