【问题标题】:How can i update value using api call?如何使用 api 调用更新值?
【发布时间】:2020-05-22 23:07:59
【问题描述】:
increment(sku){
        for (let index = 0; index < this.foods.length; index++){
            if (this.foods[index].food.sku == sku)
            {
                var food_quantity = this.foods[index].quantity++;
                var id= this.foods[index].variation.id;
                YH.api('cart', 'POST', null, function(data) {
                    console.log("ID and Quantity", id, food_quantity);
                    if(data.variation_id == id)
                    {
                        data.quantity = food_quantity;
                        console.log('test');
                    }
                });
            }
        }
    },

这是我的增量方法,当我单击增量按钮时,值会发生变化,但是当我刷新页面时,旧值仍然存在。 this is my api

知道如何使用 api 更新值吗?

【问题讨论】:

标签: javascript api postman


【解决方案1】:

我不确定我是否正确理解了您的问题,但如果您想存储更改,则需要某种存储系统:基本上,您需要一个数据库。这样,您将保存应用于变量的更改,以便下次进行 API 调用时,您将更新在上一次 API 调用期间存储在数据库中的值。

有不同类型的数据库和许多不同的解决方案。如果您使用 javascript,也许您想检查 MongoDB (https://www.mongodb.com/) 以坚持使用 JSON。

【讨论】:

    【解决方案2】:

    也许您可以运行一个更新函数来获取 API 的值? 您使用什么与 API 进行通信? 您可以将其临时存储在会话存储或本地存储中

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2017-03-14
      • 2013-02-23
      • 1970-01-01
      • 2020-01-31
      • 2021-08-17
      • 2021-01-04
      • 2021-06-25
      • 1970-01-01
      相关资源
      最近更新 更多