浏览代码

add replace state method

Evan You 9 年之前
父节点
当前提交
3fff85fdfe
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      src/index.js

+ 12 - 0
src/index.js

@@ -129,6 +129,18 @@ export class Store {
     this._setupModuleMutations(modules || this._modules)
   }
 
+  /**
+   * Replace entire state tree.
+   */
+
+  replaceState (newState) {
+    const state = this._vm._data
+    const clone = deepClone(newState)
+    Object.keys(clone).forEach(key => {
+      state[key] = clone[key]
+    })
+  }
+
   /**
    * Attach sub state tree of each module to the root tree.
    *