vuejs的离子本征角示例代码

问题描述 投票:2回答:1

使用Ionic Native,可以通过本机插件使用iBeacons:https://ionicframework.com/docs/native/ibeacon

示例代码是为使用AngularJS使用Ionic的人编写的,但是我使用的是VueJS,但我不知道如何使它工作:

示例代码的Angular版本:

import { IBeacon } from '@ionic-native/ibeacon/ngx';

constructor(private ibeacon: IBeacon) { }

...


// Request permission to use location on iOS
this.ibeacon.requestAlwaysAuthorization();
// create a new delegate and register it with the native layer
let delegate = this.ibeacon.Delegate();

// Subscribe to some of the delegate's event handlers
delegate.didRangeBeaconsInRegion()
  .subscribe(
    data => console.log('didRangeBeaconsInRegion: ', data),
    error => console.error()
  );
delegate.didStartMonitoringForRegion()
  .subscribe(
    data => console.log('didStartMonitoringForRegion: ', data),
    error => console.error()
  );
delegate.didEnterRegion()
  .subscribe(
    data => {
      console.log('didEnterRegion: ', data);
    }
  );

let beaconRegion = this.ibeacon.BeaconRegion('deskBeacon','F7826DA6-ASDF-ASDF-8024-BC5B71E0893E');

this.ibeacon.startMonitoringForRegion(beaconRegion)
  .then(
    () => console.log('Native layer received the request to monitoring'),
    error => console.error('Native layer failed to begin monitoring: ', error)
  );

但是..我期望工作的是VueJS中的以下内容:

在导入组件的顶部:import { IBeacon } from '@ionic-native/ibeacon/ngx';

并像这样使用它:

foobar() {
let _ibeacon = IBeacon.Delegate()
  alert('Hi iBeacon');
  _ibeacon.didStartMonitoringForRegion()
    .subscribe(
      data => console.log('didStartMonitoringForRegion: ', data),
      error => console.error()
    );
}

但是即使警报也没有显示。将iBeacon插件与Vue和ionic一起使用的正确方法是什么?

vue.js ionic-framework ionic4 ionic-native
1个回答
0
投票

[C0的速记]有效。只需替换两个文件。

© www.soinside.com 2019 - 2024. All rights reserved.