Skip to content

Commit

Permalink
feat(runtime-core): warn async data()
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 14, 2020
1 parent 78977c3 commit 3e7bb7d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
isArray,
EMPTY_OBJ,
NOOP,
hasOwn
hasOwn,
isPromise
} from '@vue/shared'
import { computed } from './apiComputed'
import { watch, WatchOptions, WatchCallback } from './apiWatch'
Expand Down Expand Up @@ -316,6 +317,13 @@ export function applyOptions(
)
}
const data = dataOptions.call(ctx, ctx)
if (__DEV__ && isPromise(data)) {
warn(
`data() returned a Promise - note data() cannot be async; If you ` +
`intend to perform data fetching before component renders, use ` +
`async setup() + <Suspense>.`
)
}
if (!isObject(data)) {
__DEV__ && warn(`data() should return an object.`)
} else if (instance.data === EMPTY_OBJ) {
Expand Down

0 comments on commit 3e7bb7d

Please sign in to comment.