diff --git a/src/store-util.js b/src/store-util.js index e3ba18609..4aac002cd 100644 --- a/src/store-util.js +++ b/src/store-util.js @@ -269,7 +269,8 @@ function registerGetter (store, type, rawGetter, local) { } function enableStrictMode (store) { - watch(() => store._state.data, () => { + store._strictModeWatcherUnsubscribe && store._strictModeWatcherUnsubscribe(); + store._strictModeWatcherUnsubscribe = watch(() => store._state.data, () => { if (__DEV__) { assert(store._committing, `do not mutate vuex store state outside mutation handlers.`) } diff --git a/types/index.d.ts b/types/index.d.ts index a9a94de82..570231a5d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,4 @@ -import { App, WatchOptions, InjectionKey } from "vue"; +import { App, WatchOptions, InjectionKey , WatchStopHandle } from "vue"; // augment typings of Vue.js import "./vue"; @@ -41,6 +41,8 @@ export declare class Store { getters?: GetterTree; modules?: ModuleTree; }): void; + + _strictModeWatcherUnsubscribe?: WatchStopHandle; } export const storeKey: string;