瀏覽代碼

hot reload

Evan You 9 年之前
父節點
當前提交
ffadc68d95
共有 1 個文件被更改,包括 29 次插入0 次删除
  1. 29 0
      docs/en/hot-reload.md

+ 29 - 0
docs/en/hot-reload.md

@@ -0,0 +1,29 @@
+# Hot Reloading
+
+Vuex supports hot-reloading actions and mutations during development, using Webpack's [Hot Module Replacement API](https://webpack.github.io/docs/hot-module-replacement.html). You can also use it in Browserify with the [browserify-hmr](https://github.com/AgentME/browserify-hmr/) plugin.
+
+It's as simple as calling `vuex.hotUpdate()` with the new actions and mutations:
+
+``` js
+// ...
+const vuex = new Vuex({
+  state,
+  actions,
+  mutations
+})
+
+if (module.hot) {
+  // accept actions and mutations as hot modules
+  module.hot.accept(['./actions', './mutations'], () => {
+    // require the updated modules
+    // have to add .default here due to babel 6 module output
+    const newActions = require('./actions').default
+    const newMutations = require('./mutations').default
+    // swap in the new actions and mutations
+    vuex.hotUpdate({
+      actions: newActions,
+      mutations: newMutations
+    })
+  })
+}
+```