From 6c1e48a00a6e93d89e36dcd2c1478a054d27235e Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 23 Jun 2016 13:39:36 -0400 Subject: [PATCH] support 1.x as well --- src/override.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/override.js b/src/override.js index 386bc5e0a..7bb8ba535 100644 --- a/src/override.js +++ b/src/override.js @@ -1,13 +1,29 @@ import { getWatcher, getDep } from './util' export default function (Vue) { - Vue.mixin({ init }) + var version = Number(Vue.version.split('.')[0]) + + if (version >= 2) { + Vue.mixin({ + init: vuexInit + }) + } else { + // override init and inject vuex init procedure + // for 1.x backwards compatibility. + const _init = Vue.prototype._init + Vue.prototype._init = function (options = {}) { + options.init = options.init + ? [vuexInit].concat(options.init) + : vuexInit + _init.call(this, options) + } + } /** * Vuex init hook, injected into each instances init hooks list. */ - function init () { + function vuexInit () { const options = this.$options const { store, vuex } = options // store injection