注意:必须申请 高德地图api key
1. 在public目录内的 index.html head中加入 地图api的js
伪代码
<html>
<head>
.........
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0Beta&key=您申请的Web端key值"></script>
</head>
.................
2. vue.config.js 如下
onst assetsCDN = {
// webpack build externals
externals: {
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex',
axios: 'axios',
AMap:'AMap'//重点
},
3. vueConfig 中
externals: isProd ? assetsCDN.externals : { AMap: 'AMap'} //重点 AMap: 'AMap'
使用就简单了,大体如下
import AMap from 'AMap'
..........
若不配置很容易出现以下错误
1. 上方 3 不加入,调试环境有可能不能使用,报错如下
(1)vue-router.esm.js?8c4f:2117 SyntaxError: Unexpected token '!'
(2)To install it, you can run: npm install --save AMap