Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova 从VueJS中的事件传递数据_Cordova_Vue.js_Geolocation - Fatal编程技术网

Cordova 从VueJS中的事件传递数据

Cordova 从VueJS中的事件传递数据,cordova,vue.js,geolocation,Cordova,Vue.js,Geolocation,所以,我正在用VueJS开发Cordova Android应用程序,我使用 它会发出名为“location”的全局事件,我的应用程序会在main.js中监听该事件 函数ondevicerady(){ BackgroundGeolocation.on('location',(location)=>{}) } 文档.添加的事件列表器('deviceready',onDeviceReady,false) 如何在每次触发事件时将位置数据传递给组件中的变量? 尝试在组件中的mounted方法中添加事件侦

所以,我正在用VueJS开发Cordova Android应用程序,我使用

它会发出名为“location”的全局事件,我的应用程序会在main.js中监听该事件

函数ondevicerady(){
BackgroundGeolocation.on('location',(location)=>{})
}
文档.添加的事件列表器('deviceready',onDeviceReady,false)
如何在每次触发事件时将位置数据传递给组件中的变量?

尝试在组件中的
mounted
方法中添加事件侦听器,并将其处理程序指向组件方法,如下所示:

导出默认值{
数据(){
返回{
位置:空,
}
},
安装的(){
document.addEventListener('devicerady',this.ondevicerady,false)
},
在…之前{
//记住删除事件侦听器
document.removeEventListener('devicerady',this.ondevicerady)
},
方法:{
onDeviceReady(){
BackgroundGeolocation.on('location',this.handleLocation)
},
手动位置(位置){
//你有位置!
this.location=位置
}
}
})
尝试在组件中的
mounted
方法中添加事件侦听器,并将其处理程序指向组件方法,如下所示:

导出默认值{
数据(){
返回{
位置:空,
}
},
安装的(){
document.addEventListener('devicerady',this.ondevicerady,false)
},
在…之前{
//记住删除事件侦听器
document.removeEventListener('devicerady',this.ondevicerady)
},
方法:{
onDeviceReady(){
BackgroundGeolocation.on('location',this.handleLocation)
},
手动位置(位置){
//你有位置!
this.location=位置
}
}
})

非常感谢你,你真的为我节省了很多时间!我只能添加我添加的
window.BackgroundGeolocation.on()
使它工作。非常感谢,你真的为我节省了很多时间!我只能添加我添加的
window.BackgroundGeolocation.on()
使其正常工作。