Skip to content

Commit 5afdd4f

Browse files
committed
Set default values in beforeCreate event so they
are non-null for computed functions
1 parent b2e9d37 commit 5afdd4f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const AsyncComputed = {
4848
this.$options.computed[prefix + key] = getter
4949
}
5050

51-
this.$options.data = initDataWithAsyncComputed(this.$options)
51+
this.$options.data = initDataWithAsyncComputed(this.$options, pluginOptions)
5252
},
5353
created () {
5454
for (const key in this.$options.asyncComputed || {}) {
@@ -115,7 +115,7 @@ function handleAsyncComputedPropetyChanges (vm, key, pluginOptions, Vue) {
115115
vm.$watch(prefix + key, watcher, { immediate: true })
116116
}
117117

118-
function initDataWithAsyncComputed (options) {
118+
function initDataWithAsyncComputed (options, pluginOptions) {
119119
const optionData = options.data
120120
const asyncComputed = options.asyncComputed || {}
121121

@@ -125,11 +125,13 @@ function initDataWithAsyncComputed (options) {
125125
: optionData) || {}
126126
for (const key in asyncComputed) {
127127
const item = this.$options.asyncComputed[key]
128+
129+
var value = generateDefault.call(this, item, pluginOptions)
128130
if (isComputedLazy(item)) {
129-
initLazy(data, key)
131+
initLazy(data, key, value)
130132
this.$options.computed[key] = makeLazyComputed(key)
131133
} else {
132-
data[key] = null
134+
data[key] = value
133135
}
134136
}
135137
return data

src/lazy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export function isLazyActive (vm, key) {
1111
const lazyActivePrefix = 'async_computed$lazy_active$',
1212
lazyDataPrefix = 'async_computed$lazy_data$'
1313

14-
export function initLazy (data, key) {
14+
export function initLazy (data, key, value) {
1515
data[lazyActivePrefix + key] = false
16-
data[lazyDataPrefix + key] = null
16+
data[lazyDataPrefix + key] = value
1717
}
1818

1919
export function makeLazyComputed (key) {

0 commit comments

Comments
 (0)