fix bug in vuex of strict model

This commit is contained in:
Pan
2017-07-13 16:54:54 +08:00
parent 62cb24c1a6
commit 29d28c3231
3 changed files with 31 additions and 5 deletions

View File

@@ -250,3 +250,21 @@
};
}
export function deepClone(source) {
if (!source && typeof source !== 'object') {
throw new Error('error arguments', 'shallowClone');
}
const targetObj = source.constructor === Array ? [] : {};
for (const keys in source) {
if (source.hasOwnProperty(keys)) {
if (source[keys] && typeof source[keys] === 'object') {
targetObj[keys] = source[keys].constructor === Array ? [] : {};
targetObj[keys] = deepClone(source[keys]);
} else {
targetObj[keys] = source[keys];
}
}
}
return targetObj;
}