这个项目是我用vue写的项目用在微信网页中,现在我要请求微信的位置的api然后获得经纬度参数然后再请求后台接口获得数据,我写在每个组件中是没问题的,现在我想把这个方法提出来做个公共方法来用,可是我先方法可以调用也能请求到数据,但是我在调用方法的组件中拿不到数据,下面是代码,写在一个单独的js文件中
//地理位置定位
import {getLocationUrl} from 'common/config'
import {SaveLocalStorage,GetLocalStorage} from 'common/localStorage'
import {PasswordPost} from 'common/tool'
export function GetLocationPos(){
let _this=this
return wx.ready(function(){
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
let data=JSON.stringify(res)
SaveLocalStorage('_User_Loaction_',data)
let str=res.latitude+','+res.longitude
return SendLocationAjax(str)
}
})