test('data property is already declared in props', () => {
const Comp = {
props: { foo: Number },
- data: {
+ data: () => ({
foo: 1
- },
+ }),
render() {}
}
test('computed property is already declared in data', () => {
const Comp = {
- data: {
+ data: () => ({
foo: 1
- },
+ }),
computed: {
foo() {}
},
test('methods property is already declared in data', () => {
const Comp = {
- data: {
+ data: () => ({
foo: 2
- },
+ }),
methods: {
foo() {}
},
// 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
// 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) {
it('should support using element innerHTML as template', () => {
const app = createApp({
- data: {
+ data: () => ({
msg: 'hello'
- }
+ })
})
const container = document.createElement('div')
container.innerHTML = '{{msg}}'