需求中判断页面是否编辑过的时候,可以采用比较对象属性值是否变化的方式来判断页面是否属于修改过状态
isObjectValueEqual (a, b) {
//取对象a和b的属性名
let aProps = Reflect.ownKeys(a);
let bProps = Reflect.ownKeys(b);
if (aProps.length != bProps.length) {
return false;
}
//循环取出属性名,再判断属性值是否一致
for (let i = 0; i < aProps.length; i++) {
let propName = aProps[i];
let type = typeof a[propName];
if(type === 'object'){
//值是对象类型就递归
if(!this.isObjectValueEqual(a[propName],b[propName])){
return false;
}
}else{
if(a[propName] !== b[propName]) {
return false;
}
}
}
return true
}
this.isObjectValueEqual({a:1,b:[1,2,3]},{a:1,b:[1,2,3],c:1})
false