最近在做一个 就业地图的功能,将职位、企业在地图上标注出来。当用户点击地图上的标注点的时候,要弹出信息窗口。在实现的时候,遇到了一个问题。信息窗口不能实时更新。也就是如下图展示的问题,记录下。
一、 先看一个问题
代码如下
// 查看信息窗口
lookDetail(item, event) {
const positionInfo = { lng: item.lng, lat: item.lat }
this.circleShow = false
this.$nextTick(() => {
this.circleShow = true
})
event.domEvent.stopPropagation()
this.infoWindow.show = true
this.infoWindow.data = item
this.infoWindow.position = positionInfo
},
- 分析和解决
// 查看信息窗口
lookDetail(i, event) {
const item = this.mapOptions[i]
const positionInfo = { lng: item.lng, lat: item.lat }
this.circleShow = false
this.$nextTick(() => {
this.circleShow = true
})
event.domEvent.stopPropagation()
this.infoWindow.show = true
this.infoWindow.data = item
this.infoWindow.position = positionInfo
},
- 正常效果
二、问题2
第一次点击地图上的坐标点的时候,没有反应。当第二次点击的时候,才有反应。
-
解决如下
-
正常效果