taro 填坑之路(三)taro 缓存

1.taro 缓存

/**
 * 缓存数据 H5 小程序
 * {food.id:{菜品信息 Num}, }
 */
import Taro from '@tarojs/taro';

// 取值
let store = Taro.getStorageSync(foodKey);
// 存值
Taro.setStorageSync(foodKey,store);

2.Array 的 some 和 filter

some 返回值为true/false

if(this.state.foodlist.some(item => item.pid == selectCata.id)){ // 返回值为true/false
  //
}

filtern 返回值为筛选后的新数组

this.setState({
  currentList: this.state.foodlist.filter(item => item.pid == selectCata.id) // 筛选
});

.

.

原文地址:https://www.cnblogs.com/crazycode2/p/9977081.html