App.vue 706 B

123456789101112131415161718192021222324252627282930313233
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. //开启GPS后台刷新
  5. wx.startLocationUpdate({
  6. success(resp) {
  7. console.log('开启定位成功');
  8. },
  9. fail(resp) {
  10. console.log('开启定位失败');
  11. }
  12. });
  13. //GPS定位变化就自动提交给后端
  14. wx.onLocationChange(function(resp) {
  15. let latitude = resp.latitude;
  16. let longitude = resp.longitude;
  17. let location = { latitude: latitude, longitude: longitude };
  18. //触发自定义事件
  19. uni.$emit('updateLocation', location);
  20. });
  21. },
  22. onShow: function() {
  23. console.log('App Show');
  24. },
  25. onHide: function() {
  26. console.log('App Hide');
  27. }
  28. };
  29. </script>
  30. <style lang="scss">
  31. @import 'uview-ui/index.scss';
  32. </style>