|
|
@@ -15,6 +15,7 @@ export function initState (vm) {
|
|
|
initData(vm)
|
|
|
initComputed(vm)
|
|
|
initMethods(vm)
|
|
|
+ initWatch(vm)
|
|
|
}
|
|
|
|
|
|
function initData (vm) {
|
|
|
@@ -92,6 +93,21 @@ function initMethods (vm) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function initWatch (vm) {
|
|
|
+ const watch = vm.$options.watch
|
|
|
+ if (watch) {
|
|
|
+ for (let key in watch) {
|
|
|
+ let handler = watch[key]
|
|
|
+ let options
|
|
|
+ if (typeof handler === 'object') {
|
|
|
+ handler = handler.handler
|
|
|
+ options = handler
|
|
|
+ }
|
|
|
+ vm.$watch(key, handler, options)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export function stateMixin (Vue) {
|
|
|
Object.defineProperty(Vue.prototype, '$data', {
|
|
|
get () {
|