AMap1.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div id="container"></div>
  3. </template>
  4. <script>
  5. import AMapLoader from '@amap/amap-jsapi-loader';
  6. import { shallowRef } from '@vue/reactivity'
  7. export default {
  8. data () {
  9. return {
  10. }
  11. },
  12. mounted(){
  13. //DOM初始化完成进行地图初始化
  14. this.initMap();
  15. },
  16. setup(){
  17. const map = shallowRef(null);
  18. return{
  19. map,
  20. }
  21. },
  22. methods:{
  23. initMap(){
  24. AMapLoader.load({
  25. key:"", // 申请好的Web端开发者Key,首次调用 load 时必填
  26. version:"2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  27. plugins:[''], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  28. }).then((AMap)=>{
  29. this.map = new AMap.Map("container",{ //设置地图容器id
  30. viewMode:"3D", //是否为3D地图模式
  31. zoom:5, //初始化地图级别
  32. center:[105.602725,37.076636], //初始化地图中心点位置
  33. });
  34. }).catch(e=>{
  35. console.log(e);
  36. })
  37. },
  38. }
  39. }
  40. </script>
  41. <style>
  42. #container{
  43. padding:0px;
  44. margin: 0px;
  45. width: 100%;
  46. height: 800px;
  47. }
  48. </style>