1. index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>demo</title>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=YOURKEY"></script>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
2.vue.config.js
module.exports = {
configureWebpack:{
externals: {
'AMap': 'AMap'
}
},
};
3.引用页面
<template>
<div class="map" id="container"></div>
</template>
<script>
export default {
mounted () {
this.init()
},
methods: {
init() {
let map = new AMap.Map('container', {
center: [116.397428, 39.90923],
resizeEnable: true,
zoom: 10,
})
AMap.plugin(['AMap.ToolBar', 'AMap.Scale'], function () {
map.addControl(new AMap.ToolBar())
map.addControl(new AMap.Scale())
})
}
},
};
</script>
<style scoped>
.map {
width: 500px;
height: 500px;
}
</style>