我这里使用webpack作为演示,官网链接 : https://lbs.amap.com/api/javascript-api/guide/abc/load
当然,我这里使用的是在js文件中创建一个srcipt脚本连接然后加载到文档中,你可以直接使用官网的方式,直接在html文件中直接引入。
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gao De Map</title>
</head>
<body>
<div id="container"></div>
</body>
</html>
style.css
#container {
width: 1920px;
height: 1080px;
}
index.js
import './style.css'
window.onLoad = function () {
var map = new AMap.Map('container');
}
var url = 'https://webapi.amap.com/maps?v=1.4.15&key=25d17825fa2a7ee526257759c9f02f15&callback=onLoad';
var jsapi = document.createElement('script');
jsapi.src = url;
document.head.appendChild(jsapi);
webpack配置文件我就不放出来了,我的其它博文有记录的这个配置文件
效果