data中定义一个cache对象:
data(){return {cache: {} }}
// 缓存数据
xxxCacheDataList(dataList){
const _cache = this.cache;
dataList.forEach((item) => {
_cache[item.id] = item;
});
},
dataList为后端返回的数组
通过缓存数据给另一个数组中的对象增加某个缓存数据中有的属性:
从后端返回的data中获取列表数据:
this.dataList = this.yyyGetDataList(data.notes);
// 处理数据
yyyGetOperateDataList(dataList) {
// xxx缓存数据
const _cache = this.cache;
return dataList.map((item) => {
// 给yyy列表中的每个对象增加对应的属性age
item.age= _cache[item.age].file;
return item;
});
},