微信小程序 每次请求数据都把元素放入缓存数组中

发布时间:2023-05-19 15:37:45    发布者:文昌文城莱奥网络技术工作室    浏览次数:427

// 假设这是从接口获取的数据
const newData = { id: 1, value: 'example' };

// 获取缓存数组,如果不存在则设置为空数组
const storageKey = 'dataArray';
let dataArray = wx.getStorageSync(storageKey) || [];

// 将新数据添加到缓存数组中
dataArray.push(newData);

// 保存更新后的缓存数组
wx.setStorageSync(storageKey, dataArray);