首页 > 其他分享 >基于vue+elementUI使用vue-amap高德地图

基于vue+elementUI使用vue-amap高德地图

时间:2023-06-27 13:45:29浏览次数:34  
标签:vue console log elementUI AMap https amap

首先,需要去高德地图进行注册一个 https://lbs.amap.com/?ref=https://console.amap.com/dev/index ,得到一个key

然后 安装依赖

npm install vue-amap —save

在main.js中加入

import VueAMap from 'vue-amap’;
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
key: 'YOUR_KEY’, //上面步骤提到的key复制过来
plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
v: '1.4.4'
});

template中加入

<template>     <div class="amap-wrapper">       <el-amap             ref="map"             :vid="'amapDemo'"             :center="center"             :zoom="zoom"             :plugin="plugin"             :events="events"             class="amap-demo"             style="height: 800px;width: 100%">             <el-amap-marker v-for="(u,i) in markers" :position="u.position" :key="i">             </el-amap-marker>             <el-amap-marker :position="[121.5273285, 31.21515044]" :icon="icon">            </el-amap-marker>         </el-amap>  </div> </template>
  script中加入
<script>  export default {         name: 'index',         data() {             return {                 center: [121.5273285, 31.21515044],                 zoom: 12,                 position: [121.5273285, 31.21515044],                 icon: new AMap.Icon({                                 image: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",                     size: new AMap.Size(128, 128),  //自定义地图标记点图片                     imageSize: new AMap.Size(64,64)                 }),                 events: {                     init(o){                         console.log(o.getCenter());                     },                     zoomchange: (e) => {                         console.log(e);                     },                     zoomend: (e) => {                         //获取当前缩放zoom值                         console.log(this.$refs.map.$$getInstance().getZoom());                         console.log(e);                     },                     click: e => {                         alert('map clicked')                     }                 },                 markers: [//标记点位置                     {                         position: [121.5273285, 31.21515044]                     },                     {                         position: [121.5174286, 31.21515044]                     }                 ],                //使用其他组件                 plugin: [                     {                         pName: 'Scale',                         events: {                             init(instance) {                                 console.log(instance)                             }                         }                     },                     {                         pName: 'ToolBar',                         events: {                             init(instance) {                                 console.log(instance)                             }                         }                     }                 ],             };         },         methods: {         }     } </script>
  参考https://blog.csdn.net/qq_42112618/article/details/120323519

标签:vue,console,log,elementUI,AMap,https,amap
From: https://www.cnblogs.com/luzanzan/p/17508625.html

相关文章

  • vue-element-admin 动态路由踩坑之路。。。
    参考帖子1.菜单详解(主要是加载原理,还有一些脚本,json格式的参考)https://blog.csdn.net/weixin_44922964/article/details/120927244https://blog.csdn.net/qq_57581439/article/details/1278629972.三级路由:https://www.cnblogs.com/netcore-vue/p/14911375.html(这个主要是加载......
  • vue3透传 Attributes
    “透传attribute”指的是传递给一个组件,却没有被该组件声明为props或emits的attribute或者 v-on 事件监听器。最常见的例子就是 class、style 和 id当一个组件以单个元素为根作渲染时,透传的attribute会自动被添加到根元素上A组件:<template><h3>ComponentA</......
  • Vue2电商实战项目(六)个人中心
    个人中心Center组件先搞定静态组件###router.routes.jsimportCenterfrom'@/pages/Center'exportdefault[ { name:"center", path:"/center", component:Center, meta:{ show:true } }......拆分Center组件,把我的订单和团购订单拆分成两个子路......
  • 【vue2】使用vue常见的业务流程与实现思路
     ......
  • Vue如何在页面加载时将url的参数赋值给组件
    <template> <inputv-model="loginForm.username" name="username" type="text" tabindex="1" auto-complete="on" /><inputv-model="loginForm.password":type="passwordType"......
  • 【vue2】vuex超超超级详解!(核心五大配置项)
    ......
  • 【vue2】Vue Cli脚手架与VueTools的安装详解
    ......
  • vue2中$set用法详细讲解
    1、为什么要用set?在vue中,并不是任何时候数据都是双向绑定的。在官方文档中,有这样一段话,如下: 从文档得知,当数据没有被双向绑定的时候,我们就需要使用set了2、set用法解决数据没有被双向绑定我们可以使用vm.$set实例方法,该方法是全局方法Vue.set的一个别名。this.$set(原......
  • vue3引入bootstrap5的折叠菜单无效问题解决
    问题:通过npm后者yarn安装bootstrap5后,在入口文件全局引入bootstrap5的js、scc,在vue组件引入折叠功能,点击可以正常展开,在点击无法收回解决办法:可参考网上博主的建议,大概意思就是之前引入的js文件不对,导致收回方法没有执行import'bootstrap/dist/js/bootstrap.bundle'main入口......
  • 前端Vue自定义加载中loading加载结束end组件 可用于分页展示 页面加载请求
    前端Vue自定义加载中loading加载结束end组件可用于分页展示页面加载请求,请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13219效果图如下:实现代码如下:cc-paging使用方法<!--加载中用法isLoading:是否加载isEnd:是否结束加载--><cc-paging:isLoad......