feat(runtime-core): implement RFC-0020
BREAKING CHANGE: data no longer supports object format (per RFC-0020)
This commit is contained in:
parent
dd17fa1c90
commit
bb7fa3dabc
@ -634,9 +634,9 @@ describe('api: options', () => {
|
|||||||
test('data property is already declared in props', () => {
|
test('data property is already declared in props', () => {
|
||||||
const Comp = {
|
const Comp = {
|
||||||
props: { foo: Number },
|
props: { foo: Number },
|
||||||
data: {
|
data: () => ({
|
||||||
foo: 1
|
foo: 1
|
||||||
},
|
}),
|
||||||
render() {}
|
render() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,9 +649,9 @@ describe('api: options', () => {
|
|||||||
|
|
||||||
test('computed property is already declared in data', () => {
|
test('computed property is already declared in data', () => {
|
||||||
const Comp = {
|
const Comp = {
|
||||||
data: {
|
data: () => ({
|
||||||
foo: 1
|
foo: 1
|
||||||
},
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
foo() {}
|
foo() {}
|
||||||
},
|
},
|
||||||
@ -699,9 +699,9 @@ describe('api: options', () => {
|
|||||||
|
|
||||||
test('methods property is already declared in data', () => {
|
test('methods property is already declared in data', () => {
|
||||||
const Comp = {
|
const Comp = {
|
||||||
data: {
|
data: () => ({
|
||||||
foo: 2
|
foo: 2
|
||||||
},
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
foo() {}
|
foo() {}
|
||||||
},
|
},
|
||||||
|
@ -167,7 +167,7 @@ export interface LegacyOptions<
|
|||||||
// Limitation: we cannot expose RawBindings on the `this` context for data
|
// Limitation: we cannot expose RawBindings on the `this` context for data
|
||||||
// since that leads to some sort of circular inference and breaks ThisType
|
// since that leads to some sort of circular inference and breaks ThisType
|
||||||
// for the entire component.
|
// for the entire component.
|
||||||
data?: D | ((this: ComponentPublicInstance<Props>) => D)
|
data?: (this: ComponentPublicInstance<Props>) => D
|
||||||
computed?: C
|
computed?: C
|
||||||
methods?: M
|
methods?: M
|
||||||
watch?: ComponentWatchOptions
|
watch?: ComponentWatchOptions
|
||||||
@ -280,7 +280,13 @@ export function applyOptions(
|
|||||||
|
|
||||||
// state options
|
// state options
|
||||||
if (dataOptions) {
|
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)) {
|
if (!isObject(data)) {
|
||||||
__DEV__ && warn(`data() should return an object.`)
|
__DEV__ && warn(`data() should return an object.`)
|
||||||
} else if (instance.data === EMPTY_OBJ) {
|
} else if (instance.data === EMPTY_OBJ) {
|
||||||
|
@ -89,9 +89,9 @@ describe('compiler + runtime integration', () => {
|
|||||||
|
|
||||||
it('should support using element innerHTML as template', () => {
|
it('should support using element innerHTML as template', () => {
|
||||||
const app = createApp({
|
const app = createApp({
|
||||||
data: {
|
data: () => ({
|
||||||
msg: 'hello'
|
msg: 'hello'
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
const container = document.createElement('div')
|
const container = document.createElement('div')
|
||||||
container.innerHTML = '{{msg}}'
|
container.innerHTML = '{{msg}}'
|
||||||
|
Loading…
Reference in New Issue
Block a user