0
点赞
收藏
分享

微信扫一扫

vue-baidu-map 报错 | map is undefined


 报错描述  

 给 <baidu-map></baidu-map> 绑定了地图初始化事件 @ready="initMap" 

  • 在方法 initMap({BMap, map}) {} 中 map 可以正常使用
  • 在其他方法/生命周期中,一旦使用 map,便报错提示 map is undefined

解决方案

1. 在data() 中定义map变量

data() {
return {
map: '',

2. 在方法 initMap({BMap, map}) {} 中,保存map

initMap({BMap, map}) {
this.map = map

3. 在其他方法/生命周期中使用map时,使用 this.map

举报

相关推荐

0 条评论