Browse Source

support store injection

Evan You 9 năm trước cách đây
mục cha
commit
5fe5305b89
1 tập tin đã thay đổi với 10 bổ sung0 xóa
  1. 10 0
      src/index.js

+ 10 - 0
src/index.js

@@ -223,6 +223,16 @@ export { createLogger }
 // export install function
 export function install (_Vue) {
   Vue = _Vue
+  const _init = Vue.prototype._init
+  Vue.prototype._init = function (options) {
+    options = options || {}
+    if (options.store) {
+      this.$store = options.store
+    } else if (options.parent && options.parent.$store) {
+      this.$store = options.parent.$store
+    }
+    _init.call(this, options)
+  }
 }
 
 // also export the default