vue地图加载报错:map container div not exist

参考文献:

vue地图加载报错:map container div not exist-CSDN博客

原因:

  1. 地图加载的id与html中不一致

<div id="container" style="width: 1000px; height: 700px;">

let map = new this.AMap.Map('myMap', {

center: 121.227577, 31.101471, // 中心点坐标

resizeEnable: true, // 是否监控地图容器尺寸变化

zoom: 10, // 初始化地图层级,可以理解为缩放比例

showMarker: true, // 定位成功后在定位到的位置显示点标记,默认:true

});

2.地图加载的时候dom结构还没生成,把initmap函数放到了created生命周期中加载

// 错误:

created(){

this.initMap()

}

// 改为

mounted(){

this.initMap()

}

3.地图容器所在html代码被隐藏掉了,或者之前的代码存在错误

<el-row v-if="form.attachmentInfoList.length != 0">

<el-col :span="24">

<el-form-item label="¸½¼þÐÅÏ¢">

<div class="demo-image__preview" v-for="item in form.attachmentInfoList" :key="item">

<el-image style="width: 100px; height: 100px; float:left" :src="item" :preview-src-list="form.attachmentInfoList"></el-image>

</div>

</el-form-item>

</el-col>

</el-row>

<el-row :gutter="20">

<el-col :span="24">

<div class="grid-content bg-purple">

<el-form-item label="">

<div id="mapDiv" style="width: 100%;height: 650px;border:1px solid #bfcbd9;padding: 8px;z-index: 0;"></div>

</el-form-item>

</div>

</el-col>

</el-row>

data() {

return {

form: {

// attachmentInfoList: \[\]

},

}

},

刚开始data中注销掉了form中的attachmentInfoList属性,在html中第一个row中有个判断

v-if="form.attachmentInfoList.length != 0"

此处form.attachmentInfoList为undefined,没有length属性,所以报错了

相关推荐
程序员爱钓鱼8 小时前
Rust Associated Type关联类型详解:为Trait定义内部类型
前端·后端·rust
zh_xuan9 小时前
个人主页左侧菜单支持分组,以及菜单显示和隐藏
前端·javascript·css
Ming_studying9 小时前
HTML + CSS + JavaScript实现可视化JSON工具:格式化、折叠、搜索与错误定位
javascript·css·html·json·数据可视化·web工具
Emily1568535987012 小时前
Emerson 1C31129G03 Analog Input Module
java·开发语言·前端·plc·emerson·1c31129g03·input module
To_OC17 小时前
面试被问了三回三栏布局,这次我终于把 BFC 那层窗户纸捅破了
前端·css·面试
To_OC17 小时前
啃完 TS 工具类型我发现:Pick 和 Omit 原来就是一层窗户纸
前端·面试·typescript
风月说与山鬼19 小时前
三、大括号语法
前端·react.js
kyriewen19 小时前
我把最常踩的8个CORS跨域报错整理了一遍——第8个去年还不存在
前端·javascript
Csvn20 小时前
🕰️ 闭包 + setTimeout 的 5 个经典陷阱:为什么定时器看到的永远不是最新的值?
前端