uni-app中,map组件marker图标在手机端第二次进入不显示问题
<template>
<view>
<map name="map1" id="map1" ref="map1" :longitude="longitude" :latitude="latitude" :markers="markers"></map>
</view>
</template>
export default {
props:['gdx','gdy'],
data() {
return {
longitude:'',
latitude:'',
markers:[]
}
},
mounted(){
// #ifdef APP-PLUS
this.longitude = this.gdx;
this.latitude = this.gdy;
let marker = {
id:"1",
longitude:this.gdx,
latitude:this.gdy,
iconPath:'../../static/logo.png'
}
this.markers.push(marker);
},
}
每次进入地图后坐标都是从后台获取的,所以图标每次都需要重新渲染,代码中的markers是数组每次都需要清空在重新添加坐标对象。故,只需要在代码mounted函数中的开头位置加上
this.markers=[];