Vue使用高德地圖實(shí)現(xiàn)城市定位
本文實(shí)例為大家分享了Vue使用高德地圖實(shí)現(xiàn)城市定位的具體代碼,供大家參考,具體內(nèi)容如下
一 前端選擇框點(diǎn)擊跳轉(zhuǎn)至地圖選址頁(yè)面
<van-row class="address_item"> <van-col span="6" class="item-title">收貨地址</van-col> <van-col span="18"> <p class="item"> <van-icon name="arrow" class="arrow"/> <van-icon name="location-o" /> <span><van-field v-model="mapname" placeholder="點(diǎn)擊選擇" readonly v-on:click="mapaddress"/></span> </p> </van-col> </van-row>
二 觸發(fā)點(diǎn)擊事件
mapaddress(){ et a=this.$route.query.id localStorage.setItem('names',this.names); localStorage.setItem('phone',this.phone); localStorage.setItem('addressDetail',this.addressDetail); localStorage.setItem('postalCode',this.postalCode); localStorage.setItem('checked',this.checked); this.$router.push({ path: '/mapLocation', query: {id:a,are:this.are} }) }
三 地圖選址頁(yè)面
使用ifarm內(nèi)嵌引入高德地圖組件高德地圖 注意使用地圖需要申請(qǐng)key申請(qǐng)時(shí)注意根據(jù)自己需求選擇服務(wù)
<template> <iframe id="getAddress" @load="loadiframe" src="https://m.amap.com/picker/?keywords=寫字樓,小區(qū),學(xué)校&zoom=15¢er=&radius=1000&total=20&key=你申請(qǐng)的key" style="width:100%; height:100%;position: absolute;z-index:22222;"> </iframe> </template>
四 地圖加載完成選擇地址后跳轉(zhuǎn)至父頁(yè)面
由于我的需求在輸入后跳轉(zhuǎn)父頁(yè)面,父頁(yè)面的表單會(huì)刷新,所以做了一個(gè)緩存處理。
loadiframe() { let iframe = document.getElementById('getAddress').contentWindow; iframe.postMessage('hello', 'https://m.amap.com/picker/'); window.addEventListener("message", function (e) { if (e.data.command != "COMMAND_GET_TITLE") { //實(shí)現(xiàn)業(yè)務(wù)代碼 let a=this.$route.query.id let are=this.$route.query.are let address=e.data.address let location=e.data.location let name=e.data.name this.$router.push({ path: '/addressFill', query: {address:address,location:location,name:name,id:a,are:are} }) } }.bind(this), false); },
五 緩存處理
在跳轉(zhuǎn)子地圖選擇頁(yè)面時(shí)將表單數(shù)據(jù)存入緩存,子頁(yè)面跳轉(zhuǎn)回來時(shí)當(dāng)前頁(yè)面表單數(shù)據(jù)不刷新。
localStorage.setItem('names',this.names); localStorage.setItem('phone',this.phone); localStorage.setItem('addressDetail',this.addressDetail); localStorage.setItem('postalCode',this.postalCode); localStorage.setItem('checked',this.checked);
六 清除緩存
緩存解決了頁(yè)面返回?zé)o數(shù)據(jù)的情況,但是同時(shí)會(huì)產(chǎn)生這個(gè)頁(yè)面的緩存一直存在,所以,在返回當(dāng)前頁(yè)面時(shí)進(jìn)行驗(yàn)證,并清除緩存
let addressDetail= localStorage.getItem('addressDetail'); if(addressDetail!=undefined&&addressDetail!=null&&addressDetail!=""){ this.addressDetail=addressDetail localStorage.removeItem("addressDetail"); }else{ this.addressDetail="" }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue.js中數(shù)組變動(dòng)的檢測(cè)詳解
這篇文章給大家主要介紹了Vue.js中數(shù)組變動(dòng)的檢測(cè),文中給出了詳細(xì)的示例代碼和過程介紹,相信會(huì)對(duì)大家的理解和學(xué)習(xí)很有幫助,有需要的朋友們下面來一起看看吧。2016-10-10使用Vue3創(chuàng)建多布局系統(tǒng)的三種方法
布局是中大型網(wǎng)站或應(yīng)用的基礎(chǔ),假設(shè)你正在創(chuàng)建一個(gè)網(wǎng)頁(yè)應(yīng)用,它包括主頁(yè)、營(yíng)銷頁(yè)面和應(yīng)用頁(yè)面,你不會(huì)想要為每一頁(yè)重復(fù)所有的工作,對(duì)吧,與Nuxt不同,Vue 3并沒有內(nèi)置的布局系統(tǒng),但是別擔(dān)心,這里將向你展示3種簡(jiǎn)單的方法來實(shí)現(xiàn)這一點(diǎn),需要的朋友可以參考下2023-08-089102年webpack4搭建vue項(xiàng)目的方法步驟
這篇文章主要介紹了9102年webpack4搭建vue項(xiàng)目的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02