如何修复错误'WooCommerce.get(...)。然后不是函数?'

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

我正在尝试使用WooCommerce API-Node.js Client,它看起来非常简单。

但是当我从WooCommerce官方网站复制一个简单的示例时,出现以下错误:

TypeError: WooCommerce.get(...).then is not a function

这里是代码:

var WooCommerceAPI = require('woocommerce-api');

var WooCommerce = new WooCommerceAPI({
  url: 'https://somewebsite.com/',
  consumerKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  consumerSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  wpAPI: true,
  version: 'wc/v1'
});

WooCommerce.get("products/1359")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });

https://woocommerce.github.ioNPM package

javascript node.js woocommerce woocommerce-rest-api
1个回答
0
投票

已在NPM软件包页面的底部找到了此内容:

每个方法都可以通过仅将Async添加到方法名称的方式来使用。像在:

WooCommerce.getAsync('products').then(function(result) {
  return JSON.parse(result.toJSON().body);
});

实际上使代码现在可以正常工作。

我仍然想了解自己在做错什么,我不认为WooCommerce的官方API文档网站将所有代码示例都显示为错误。

我想它必须与WooCommerce.get一起做一些事情而不返回承诺,但这再次是它在文档中的方式。

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