]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(runtime-core): warn async data()
authorEvan You <yyx990803@gmail.com>
Tue, 14 Apr 2020 21:40:41 +0000 (17:40 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 14 Apr 2020 21:40:41 +0000 (17:40 -0400)
packages/runtime-core/src/componentOptions.ts

index ffd086983df4fe6d6858bfa4bbaa307dd7dbfabc..31bb01ad0efa9978ab5c415fc84af8bdf11d177e 100644 (file)
@@ -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() + <Suspense>.`
+      )
+    }
     if (!isObject(data)) {
       __DEV__ && warn(`data() should return an object.`)
     } else if (instance.data === EMPTY_OBJ) {