简体   繁体   English

如何使用 api 调用更新值?

[英]How can i update value using api call?

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 increment method when i click on increment button the values changes but when i refresh the page the old value still remain.这是我的增量方法,当我单击增量按钮时,值会发生变化,但是当我刷新页面时,旧值仍然存在。 this is my api这是我的 api

any idea how can i update the value using api?知道如何使用 api 更新值吗?

Maybe you could run an update function that get's the value out of the API?也许您可以运行更新 function 以获取 API 的值? What do you use to communicate with the API?您使用什么与 API 进行通信? You could temporarily store it in the session storage or localStorage您可以将其临时存储在 session 存储或 localStorage

I'm not sure I understand your question properly, but if you want to store your changes, you will need some kind of storage system: basically, you need a database.我不确定我是否正确理解了您的问题,但是如果您想存储更改,则需要某种存储系统:基本上,您需要一个数据库。 This way, you'll save changes applied to your variables so the next time you make an API call, you will update the values that you stored in your database during the previous API call.这样,您将保存应用于变量的更改,以便下次进行 API 调用时,您将更新在上一次 API 调用期间存储在数据库中的值。

There are different types of databases and many different solutions.有不同类型的数据库和许多不同的解决方案。 If you work with javascript, maybe you want to check MongoDB ( https://www.mongodb.com/ ) to stick with JSON. If you work with javascript, maybe you want to check MongoDB ( https://www.mongodb.com/ ) to stick with JSON.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用AJAX API后如何更新Angular控制器? - How can I update an Angular controller after an AJAX API call? 如何使用Jest在vuejs中测试API调用? - How can i test an API call in vuejs using jest? 如何进行依赖于另一个调用设置的值的 API 调用? - How can I make an API call that depends on a value which is set by another call? 如何使用我使用 fetch API 调用检索到的数据更新 Reactjs 状态? - How do I update Reactjs State with data I retrieved using a fetch API call? 如何使用ui-grid更新列值 - How can i update column value using ui-grid 如何在 vue 3 中不触发 @update:modelValue 的情况下将 ref 设置为 ajax 调用的值? - How can I set a ref to the value of an ajax call without triggering @update:modelValue in vue 3? 从API调用中,如何获取字段并查看该值被重复多少次? - From an API call, how can I grab a field and see how many times that value is being repeated? 如何将其格式化为RESTful API调用? - How can I format this as a RESTful API call? 如何在 Shopify 中调用 API? - How can I call an API in Shopify? Is there a way I can call an API from an api in express the parameter value in axios is undefined how do i add parameters in axios from a variable - Is there a way I can call an API from an api in express the parameter value in axios is undefined how do i add parameters in axios from a variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM