```
const vm = new Vue({
el: "#root",
data() {
return {
list: [{
id: 1,
name: 'air',
age: 23,
height: 23
},
{
id: 2,
name: 'ar',
age: 26,
height: 30
},
{
id: 3,
name: 'ai',
age: 27,
height: 43
}
],
list2: [{
id: 1,
name: 'air',
age: 23,
height: 23
},
{
id: 2,
name: 'ar',
age: 26,
height: 30
},
{
id: 3,
name: 'ai',
age: 27,
height: 43
}
],
obj: {
id: 0,
name: '',
age: 0,
height: 0
},
ss: [],
rowIndex: 0
}
},
created() {
this.getData();
// 过滤后累加的数据,伪数组形式
this.handle(this.list);
// 处理操作,filter和map都会改变原数组,这里是map
this.changeData(this.list);
// 赋值操作
this.ss = this.list;
// 处理操作,filter和map都会改变原数组,同上,这里是filter
this.inCreace(this.list2);
},
methods: {
// 编辑数组对象,传递一行数据过来
editUser(item, index) {
this.rowIndex = index;
this.obj = {
id: item.id,
name: item.name,
age: item.age,
height: item.height
}
},
// 累加处理
handle(array) {
return array.map(item => {
const obj = {};
obj.name = item.name;
obj.children = [
item.age > 23 ? item.age : 0,
item.height > 30 ? item.height : 0
]
obj.total = obj.children.reduce((pre,cur) => pre+cur);
return obj;
});
console.log(this.ss,'ssb');
},
// map遍历数组返回修改的对象key值名字
changeData(array) {
return array.map(item => {
item.name == 'air' ? item.name = 'AIR': item
});
},
// filter遍历数组返回修改的对象key值名字
inCreace(array) {
return array.filter(item => {
return item.name == 'air' ? item.name = 'AIR': item
});
}
}
})
```