From 687047f7d7c6dc690e2f2da7ed1bdd05b45e9724 Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Mon, 15 Apr 2024 15:30:10 +0800 Subject: [PATCH] flat: jsonp --- api/map.js | 25 ++++++++++++++++++++----- main.js | 7 ++++--- package-lock.json | 5 +++++ package.json | 3 ++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/api/map.js b/api/map.js index bbfdb2a..f22f9a7 100644 --- a/api/map.js +++ b/api/map.js @@ -3,15 +3,30 @@ import { } from '@/untils/AxiosUtils.js'; /*逆地址解析*/ export const getcoder = (location, key, get_poi) => { - return request({ - url: 'https://apis.map.qq.com/ws/geocoder/v1', - method: 'get', - params: { + return new Promise((resolve, reject) => { + const paramsData = { location, key, - get_poi + get_poi, + output: 'jsonp' } + jsonp('https://apis.map.qq.com/ws/geocoder/v1', paramsData, 30000) + .then((response) => { + console.log('response', response) + resolve(response) + }).catch(err => { + reject(err) + }) }) + // return request({ + // url: 'https://apis.map.qq.com/ws/geocoder/v1', + // method: 'get', + // params: { + // location, + // key, + // get_poi + // } + // }) } /*关键词输入提示*/ diff --git a/main.js b/main.js index b423b03..3d91d00 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,9 @@ import App from './App' import util from './untils/func.js' import uView from '@/uni_modules/uview-ui' import config from './config'; - +import { + VueJsonp +} from 'vue-jsonp' // 注册全局组件 // import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue" // import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue" @@ -42,14 +44,13 @@ Vue.component('jl-form', JlForm) Vue.component('jl-form-item', JlFormItem) Vue.component('cs-button', CSButton) Vue.component('empty', empty) - Vue.prototype.$api = { msg } Vue.prototype.$config = config Vue.prototype.navTo = navTo Vue.config.productionTip = false - +Vue.use(VueJsonp) Vue.use(util) Vue.use(uView) diff --git a/package-lock.json b/package-lock.json index bc83aa1..9e63bf5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,11 @@ "version": "0.7.3", "resolved": "https://r.cnpmjs.org/js-md5/download/js-md5-0.7.3.tgz", "integrity": "sha1-tPL7sLMnRV9ZjWcn447Ccs0Jw/I=" + }, + "vue-jsonp": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/vue-jsonp/-/vue-jsonp-2.0.0.tgz", + "integrity": "sha512-Mzd9GNeuKP5hHFDWZNMWOsCuMILSkA6jo2l4A02wheFz3qqBzH7aSEFTey1BRCZCLizlaf1EqJ5YUtF392KspA==" } } } diff --git a/package.json b/package.json index 2e3c488..67b5081 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "decimal.js": "^10.2.0", "js-base64": "^2.4.9", - "js-md5": "^0.7.3" + "js-md5": "^0.7.3", + "vue-jsonp": "^2.0.0" } }