示例
const state = {
search: {
key1: 'value1',
key2: 'value2',
key3: 'value3'
}
};
// 保存初始状态的副本
const initialState = JSON.parse(JSON.stringify(state.search));
console.log('Initial state:', initialState);
// 模拟对对象的修改
state.search.key1 = 'newValue1';
state.search.key2 = 'newValue2';
console.log('Modified state:', state.search);
// 还原对象到初始状态
state.search = JSON.parse(JSON.stringify(initialState));
console.log('Restored state:', state.search);