方法一: 遍历对象属性值
hasChange: false,
compareForm(nowVal) {
var oldVal = this.copyForm
for (const i in nowVal) {
if (nowVal[i] !== oldVal[i]) {
this.hasChange = true
break
} else {
this.hasChange = false
}
}
console.log(this.hasChange)
},
方法二:lodash的isEqual,官网示例
var object = { 'a': 1 };
var other = { 'a': 1 };
_.isEqual(object, other);
// => true
object === other;
// => false
方法三: JSON.stringify()
var object = { 'a': 1 };
var other = { 'a': 2 };
JSON.stringify(object) === JSON.stringify(other);
// => true