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属性,所以报错了

相关推荐
Jolyne_5 分钟前
Taro小程序接入微信客服过程记录
前端
勇往直前plus6 分钟前
前端三基石:从后端视角理解 HTML、CSS 与 JavaScript
前端·css·html
用户693717500138418 分钟前
Google 推 AppFunctions:手机上的 AI 终于能自己干活了
android·前端·人工智能
用户693717500138435 分钟前
AI让编码变简单,真正拉开差距的是UI设计和产品思考
android·前端·人工智能
孟祥_成都39 分钟前
别再吹牛了,100% Vibe Coding 存在无法自洽的逻辑漏洞!
前端·ai编程·vibecoding
ai超级个体1 小时前
别再吹牛了,100% Vibe Coding 存在无法自洽的逻辑漏洞!
前端·ai·ai编程·vibe coding
Mike_jia2 小时前
🎓 OpenMAIC 终极指南:清华开源的多智能体 AI 互动课堂平台
前端
踩着两条虫2 小时前
告别低代码“黑盒”!VTJ.PRO 2.0:用AI与自由重塑Vue3开发
前端·低代码·ai编程
OpenTiny社区2 小时前
WebAgent :基于 MCP 协议打造的智能应用“超级路由器”
前端·agent·mcp
吴声子夜歌2 小时前
TypeScript——模块解析
javascript·ubuntu·typescript