From ff040a1db1997f79f5b388f2c223d9f20c78f5e8 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Sat, 8 Sep 2018 15:46:43 +0200 Subject: [PATCH] fix: added setter for intial value, closes #333 --- src/mixin.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mixin.js b/src/mixin.js index 8ef013c..c725fea 100644 --- a/src/mixin.js +++ b/src/mixin.js @@ -30,6 +30,7 @@ function proxyData () { let apollo = this.$options.apollo if (apollo) { + this.$_apolloInitData = {} // watchQuery for (let key in apollo) { if (key.charAt(0) !== '$') { @@ -38,6 +39,8 @@ function proxyData () { if (!options.manual && !hasProperty(this.$options.props, key) && !hasProperty(this.$options.computed, key) && !hasProperty(this.$options.methods, key)) { Object.defineProperty(this, key, { get: () => this.$data.$apolloData.data[key], + // For component class constructor + set: value => this.$_apolloInitData[key] = value, enumerable: true, configurable: true, }) @@ -81,6 +84,11 @@ function launch () { configurable: true, }) + // Init data + for (let key in this.$_apolloInitData) { + this.$set(this.$data.$apolloData.data, key, this.$_apolloInitData[key]) + } + // watchQuery for (let key in apollo) { if (key.charAt(0) !== '$') {