This article shares the specific code of Vue using Amap to realize city positioning for your reference. The specific content is as follows Click on the front-end selection box to jump to the map site selection page <van-row class="address_item"> <van-col span="6" class="item-title">Delivery address</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="Click to select" readonly v-on:click="mapaddress"/></span> </p> </van-col> </van-row> Second, trigger the click event 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} }) } Three map site selection pages Use ifarm to embed the Amap component. Amap Note that you need to apply for a key to use the map. When applying, please choose the service according to your needs. <template> <iframe id="getAddress" @load="loadiframe" src="https://m.amap.com/picker/?keywords=Office building, community, school&zoom=15¢er=&radius=1000&total=20&key=the key you applied for" style="width:100%; height:100%;position: absolute;z-index:22222;"> </iframe> </template> 4. After the map is loaded, select the address and jump to the parent page Since my requirement is to jump to the parent page after input, the form of the parent page will be refreshed, so a cache process is done. 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") { //Implement business code 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); }, 5. Cache Processing When jumping to the sub-map selection page, the form data is stored in the cache. When the sub-page jumps back, the current page form data is not refreshed. 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); 6. Clear the cache Caching solves the problem of a page returning no data, but at the same time, the cache of this page will always exist. Therefore, verification is performed when returning the current page, and the cache is cleared. let addressDetail = localStorage.getItem('addressDetail'); if(addressDetail!=undefined&&addressDetail!=null&&addressDetail!=""){ this.addressDetail=addressDetail localStorage.removeItem("addressDetail"); }else{ this.addressDetail="" } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: mysql: [ERROR] unknown option '--skip-grant-tables'
>>: Detailed tutorial on uploading and configuring jdk and tomcat on linux
Table of contents 1. Developer Platform Configura...
This article mainly introduces the differences be...
Table of contents Zabbix custom monitoring nginx ...
1. Basics of Linux Firewall The Linux firewall sy...
I have encountered the Nginx 502 Bad Gateway erro...
Copy code The code is as follows: <HTML> &l...
I've been using Bootstrap to develop a websit...
Table of contents Kill instruction execution prin...
introduction During the front-end project develop...
This article example shares the specific code of ...
After learning the basic operations of Docker, we...
Table of contents 1. Page Rendering 2. Switch tag...
Preface When using RabbitMQ, if there is no traff...
Table of contents Overview 0. JavaScript and Web ...
First query table structure (sys_users): SELECT *...