Maps.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div id="map" :style="{ width: mapWidth, height: mapHeight }"></div>
  3. </template>
  4. <script>
  5. import AMapLoader from "@amap/amap-jsapi-loader";
  6. export default {
  7. props: {
  8. width: {
  9. type: [Number, String],
  10. default: "",
  11. },
  12. height: {
  13. type: [Number, String],
  14. default: "50%",
  15. },
  16. },
  17. data() {
  18. return {};
  19. },
  20. computed: {
  21. mapWidth() {
  22. let width = this.width;
  23. if (typeof width === "number") {
  24. width = width + "px";
  25. }
  26. return width;
  27. },
  28. mapHeight() {
  29. let height = this.height;
  30. if (typeof height === "number") {
  31. height = height + "px";
  32. }
  33. return height;
  34. },
  35. },
  36. mounted() {
  37. this.initMap();
  38. },
  39. methods: {
  40. initMap() {
  41. AMapLoader.load({
  42. key: "40f1ba8477c8eb7f56397febfcd2a656", // 申请好的Web端开发者Key,首次调用 load 时必填
  43. version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  44. AMapUI: {
  45. version: "1.1",
  46. },
  47. plugins: [
  48. "AMap.AutoComplete",
  49. "AMap.PlaceSearch",
  50. "AMap.Scale",
  51. "AMap.OverView",
  52. "AMap.ToolBar",
  53. "AMap.MapType",
  54. "AMap.PolyEditor",
  55. "AMap.CircleEditor",
  56. "AMap.DistrictSearch",
  57. "AMap.RangingTool",
  58. "AMap.MarkerCluster",
  59. "AMap.IndexCluster",
  60. "AMap.Geocoder",
  61. ], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  62. })
  63. .then((AMap) => {
  64. this.$emit("callback", AMap);
  65. })
  66. .catch((e) => {
  67. console.log(e);
  68. });
  69. },
  70. },
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. #map {
  75. padding: 0px;
  76. margin: 20px 10px 10px 10px;
  77. }
  78. </style>