这个是因为请求腾讯地图api导致跨域错误解决办法就是使用uniapp终端安装vue-jsonp

	import {
		jsonp
	} from 'vue-jsonp'; //安装完成组件引用

//使用
			jumpMap() {
				let that = this;
				uni.chooseLocation({
					success: function(res) {
						that.cascade = res.address;
						that.lat = res.latitude;
						that.lng = res.longitude;
						let url = 'https://apis.map.qq.com/ws/geocoder/v1/';
						jsonp(url, {
							key: 'M7VBZ-ONPCM-TCB63-6RKVK-UCMMO-65FTP',
							location: res.latitude + ',' + res.longitude,
							output: 'jsonp'
						}).then(res => {
							console.log('jsonp', res.result.address_component);
							let {
								province,
								city,
								district
							} = res.result.address_component;
							that.province = province;
							that.city = city;
							that.area = district;
							console.log(province, city, district);

						})
					}
				});
			},

//主要是这段代码
						let url = 'https://apis.map.qq.com/ws/geocoder/v1/';
						jsonp(url, {
							key: 'M7VBZ-ONPCM-TCB63-6RKVK-UCMMO-65FTP',
							location: res.latitude + ',' + res.longitude,
							output: 'jsonp'
						}).then(res => {
							console.log('jsonp', res.result.address_component);
							let {
								province,
								city,
								district
							} = res.result.address_component;
							that.province = province;
							that.city = city;
							that.area = district;
							console.log(province, city, district);

						})

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐