瀏覽代碼

refactor: use `app.config.globalProperties` to inject store instance to vue app

Since the installation process became very slim, removed mixin.js to just include it in store file.
Kia Ishii 5 年之前
父節點
當前提交
7c19049005
共有 2 個文件被更改,包括 3 次插入17 次删除
  1. 0 15
      src/mixin.js
  2. 3 2
      src/store.js

+ 0 - 15
src/mixin.js

@@ -1,15 +0,0 @@
-import { storeKey } from './injectKey'
-
-export default function (app, store, injectKey) {
-  app.provide(injectKey || storeKey, store)
-
-  app.mixin({
-    beforeCreate () {
-      if (!this.parent) {
-        this.$store = typeof store === 'function' ? store() : store
-      } else {
-        this.$store = this.parent.$options.$store
-      }
-    }
-  })
-}

+ 3 - 2
src/store.js

@@ -1,5 +1,5 @@
 import { reactive, computed, watch } from 'vue'
-import applyMixin from './mixin'
+import { storeKey } from './injectKey'
 import devtoolPlugin from './plugins/devtool'
 import ModuleCollection from './module/module-collection'
 import { forEachValue, isObject, isPromise, assert, partial } from './util'
@@ -65,7 +65,8 @@ export class Store {
   }
 
   install (app, injectKey) {
-    applyMixin(app, this, injectKey)
+    app.provide(injectKey || storeKey, this)
+    app.config.globalProperties.$store = this
   }
 
   get state () {