我在本地存盤中存盤了物件想要更新它并再次存盤它我該怎么做?
這是物件
{
"id": 123,
"deal_id": 88,
"internal_control_number": "345678",
"export": 1,
"exportation": 0,
"organic": 0,
"national": 1,
"date_of_work": "2021-11-16",
"agent": "26911",
"ranch": null,
"weighing_machine": "34",
"type_of_cut": "23",
"type_of_damage": "19",
"boss_amount": 0,
"cutting_company_amount": 0,
"cutting_company_amount_type": null,
"packaging_company_amount": 0,
"packaging_company_amount_type": null,
"number_of_boxes": "27",
"size_of_boxes": "29",
"fruit_delivery_location": "Empaque",
"company_or_contractor": 0,
"meeting_type": "ranch",
"delivery_latitude": null,
"delivery_longitude": null,
"cutting_company": "21308",
"packaging_company": "21128",
"independent_contractor": null,
"cutting_amount": null,
"amount_of_kg": -555,
"final_kg": 0,
initial_kg: 555,
}
我想更新兩個屬性initial_kg和final_kg,然后再保存它。
我如何從煤炭存盤中獲取物件
let offline_work_order = await JSON.parse( this.$localStorage.get(`work_order_${this.id}`));
我如何在本地存盤中設定物件
this.$localStorage.set( `work_order_${this.id}`,JSON.stringify(this.work_order));
唯一的事情是修改兩個屬性
uj5u.com熱心網友回復:
如果您只想修改并放回...
代碼:
let data = JSON.parse(this.$localStorage.get(`work_order_${this.id}`));
data.initial_kg = "Your value here";
data.final_kg = "Your value here";
this.$localStorage.set(`work_order_${this.id}`, JSON.stringify(data));
// But maybe you could (Vanilla)
let data = JSON.parse(localStorage.getItem(`work_order_${this.id}`));
data.initial_kg = "Your value here";
data.final_kg = "Your value here";
localStorage.setItem(`work_order_${this.id}`, JSON.stringify(data));
// Also, JSON parse and stringify aren't async methods, use them without await.
希望這是你想要的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/361581.html
標籤:javascript Vue.js 目的
