From 3e7bb7d110818d7b90ca4acc47afc30508f465b7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 14 Apr 2020 17:40:41 -0400 Subject: [PATCH] feat(runtime-core): warn async data() --- packages/runtime-core/src/componentOptions.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index ffd086983df..31bb01ad0ef 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -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' @@ -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() + .` + ) + } if (!isObject(data)) { __DEV__ && warn(`data() should return an object.`) } else if (instance.data === EMPTY_OBJ) {