我尝试在Ionic4应用程序中使用API,在我的主页导入API后,我在输出屏幕上看不到任何东西,下面是代码:
home.page.ts
import { Component } from '@angular/core';
import * as WC from '@woocommerce/woocommerce-rest-api';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
//Local Objet WooCommerce of type any
WooCommerce: any;
constructor() {
this.WooCommerce = WC({
url: "https://shop.example.com",
consumerKey: "ck_fc057c56e5b430c9f4be64c86225e11943647ca1",
consumerSecret: "cs_12842c6e3c1122e9a17cb5c6b4e33aca3e0199528",
});
this.WooCommerce.getAsync("products").then( (data) => {
console.log(data);
}, (err) => {
console.log(err)
})
}
}使用这个新的离子应用程序接口,当我导入这个接口时,我的WooCommerce应用程序的主页就消失了。当我注释这段代码时,它再次出现。下面是我导入和使用它的方法。在运行这段代码后,我在控制台输出中得到了如下结果:
发布于 2019-09-22 23:13:48
根据您的屏幕截图,您遇到了未定义global的问题。
使用下面这一行自己定义全局的解决方案seems to be:
(window as any).global = window;打开/src/polyfills.ts并将其添加到底部:
// BUG FIX: Add global to window, assigning the value of window itself.
// https://github.com/socketio/socket.io-client/issues/1166#issuecomment-386195105
(window as any).global = window;https://stackoverflow.com/questions/58039777
复制相似问题