【问题标题】:ERROR Error: Uncaught (in promise): MyPlugin does not have web implementationERROR 错误:未捕获(承诺中):MyPlugin 没有 Web 实现
【发布时间】:2019-09-24 06:56:17
【问题描述】:

我为 iOS、Android 和 Web (PWA) 制作了一个自定义电容器插件,但是当我在浏览器中打开基于电容器的应用时,我收到以下错误消息:

ERROR Error: Uncaught (in promise): MyPlugin does not have web implementation.

所以问题接缝是Capacitor没有找到插件的web实现。

【问题讨论】:

标签: ios angular ionic-framework progressive-web-apps capacitor


【解决方案1】:

我在运行 Capacitor v2.4.7 时遇到了这个问题。它似乎是由 Plugins 对象的解构引起的:

const {MyPlugin} = Plugins;
MyPlugin.myMethod(); // FAIL

我发现使用Plugins对象直接避免了错误:

Plugins.MyPlugin.myMethod(); // OK

来源:https://github.com/ionic-team/capacitor/issues/749#issuecomment-479781137

【讨论】:

    【解决方案2】:

    要在 Angular 应用程序中修复它,您必须在 app.component.ts 中添加以下行:

    import {Component} from '@angular/core';
    
    import {MyPlugin} from "capacitor-myplugin";
    import {registerWebPlugin} from "@capacitor/core";
    
    @Component({
       selector: 'app-root',
       templateUrl: 'app.component.html'
    })
    export class AppComponent {
        constructor() {
            this.initializeApp();
        }
    
        initializeApp() {
            this.platform.ready().then(() => {
                registerWebPlugin(MyPlugin);
            });
        }
    }
    

    www.onexip.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-22
      • 2018-06-06
      • 1970-01-01
      • 2022-11-11
      • 2021-07-14
      • 2021-03-25
      • 2018-02-27
      • 2021-11-28
      相关资源
      最近更新 更多