1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| <template> <el-dialog width="65%" :append-to-body="true" :modal-append-to-body="false" title="地图" :visible="show" :before-close="close" > <div> <div class="search"> <el-input id="tipinput" v-model="searchText"></el-input> </div> <div id="amap"></div> </div> <span slot="footer" class="dialog-footer"> <el-button @click="close">取 消</el-button> <el-button type="primary" @click="ok">确 定</el-button> </span> </el-dialog> </template>
<script>
export default { name: "Amap", props: { show: { type: Boolean, default: false, }, }, data() { return { map: null, searchText: "", data: {}, }; }, mounted() { console.log("高德地图:", AMap); }, watch: { show(now, old) { if (now) { this.$nextTick(() => { this.amap(); }); } }, }, methods: { amap() { this.map = new AMap.Map("amap", { resizeEnable: true, zoom: 11, center: [116.397428, 39.90923], });
this.map.plugin(["AMap.ToolBar"], function () { this.map.addControl(new AMap.ToolBar()); }); if (location.href.indexOf("&guide=1") !== -1) { this.map.setStatus({ scrollWheel: false }); }
this.click();
var auto = new AMap.Autocomplete({ input: "tipinput", }); }, click() { const that = this; this.map.on("click", function (e) { console.log(e); that.data = e; }); }, close() { this.$emit("close", false); }, ok() { this.$emit("ok", this.data); this.close(); }, }, }; </script>
<style lang="less" scoped> #amap { width: 100%; height: 60vh; } </style>
|