feat(runtime-core): implement RFC-0020

BREAKING CHANGE: data no longer supports object format (per RFC-0020)
This commit is contained in:
Evan You
2020-03-12 16:13:12 -04:00
parent dd17fa1c90
commit bb7fa3dabc
3 changed files with 16 additions and 10 deletions

View File

@@ -167,7 +167,7 @@ export interface LegacyOptions<
// Limitation: we cannot expose RawBindings on the `this` context for data
// since that leads to some sort of circular inference and breaks ThisType
// for the entire component.
data?: D | ((this: ComponentPublicInstance<Props>) => D)
data?: (this: ComponentPublicInstance<Props>) => D
computed?: C
methods?: M
watch?: ComponentWatchOptions
@@ -280,7 +280,13 @@ export function applyOptions(
// state options
if (dataOptions) {
const data = isFunction(dataOptions) ? dataOptions.call(ctx) : dataOptions
if (__DEV__ && !isFunction(dataOptions)) {
warn(
`The data option must be a function. ` +
`Plain object usage is no longer supported.`
)
}
const data = dataOptions.call(ctx)
if (!isObject(data)) {
__DEV__ && warn(`data() should return an object.`)
} else if (instance.data === EMPTY_OBJ) {