首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入并使用WooCommerce接口后出现空屏

导入并使用WooCommerce接口后出现空屏
EN

Stack Overflow用户
提问于 2019-09-21 19:21:57
回答 1查看 43关注 0票数 1

我尝试在Ionic4应用程序中使用API,在我的主页导入API后,我在输出屏幕上看不到任何东西,下面是代码:

home.page.ts

代码语言:javascript
复制
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应用程序的主页就消失了。当我注释这段代码时,它再次出现。下面是我导入和使用它的方法。在运行这段代码后,我在控制台输出中得到了如下结果:

https://prntscr.com/p8kbmy

EN

回答 1

Stack Overflow用户

发布于 2019-09-22 23:13:48

根据您的屏幕截图,您遇到了未定义global的问题。

使用下面这一行自己定义全局的解决方案seems to be

代码语言:javascript
复制
(window as any).global = window;

打开/src/polyfills.ts并将其添加到底部:

代码语言:javascript
复制
// 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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58039777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档