calls.push('mixinA created')
expect(this.a).toBe(1)
expect(this.b).toBe(2)
- expect(this.c).toBe(3)
+ expect(this.c).toBe(4)
},
mounted() {
calls.push('mixinA mounted')
expect(this.a).toBe(1)
expect(this.b).toBe(2)
expect(this.bP).toBeUndefined()
- expect(this.c).toBe(3)
+ expect(this.c).toBe(4)
expect(this.cP1).toBeUndefined()
},
mounted() {
},
created() {
calls.push('mixinC created')
- expect(this.c).toBe(3)
+ // component data() should overwrite mixin field with same key
+ expect(this.c).toBe(4)
expect(this.cP1).toBeUndefined()
},
mounted() {
mixins: [defineComponent(mixinA), defineComponent(mixinB), mixinC],
data() {
return {
+ c: 4,
z: 4
}
},
expect(this.a).toBe(1)
expect(this.b).toBe(2)
expect(this.bP).toBeUndefined()
- expect(this.c).toBe(3)
+ expect(this.c).toBe(4)
expect(this.cP2).toBeUndefined()
expect(this.z).toBe(4)
},
return `${this.a}${this.b}${this.c}`
}
})
- expect(renderToString(h(Comp))).toBe(`123`)
+ expect(renderToString(h(Comp))).toBe(`124`)
expect(calls).toEqual([
'mixinA created',
'mixinB created',
const Base = {
data() {
return {
- a: 1
+ a: 1,
+ b: 1
}
},
methods: {
const Base = {
data() {
return {
- a: 1
+ a: 1,
+ x: 'base'
}
},
methods: {
calls.push('base')
}
}
- const Base2 = {
+ const Mixin = {
data() {
return {
- b: true
+ b: true,
+ x: 'mixin'
}
},
mounted(this: any) {
expect(this.a).toBe(1)
expect(this.b).toBeTruthy()
expect(this.c).toBe(2)
- calls.push('base2')
+ calls.push('mixin')
}
}
const Comp = defineComponent({
extends: defineComponent(Base),
- mixins: [defineComponent(Base2)],
+ mixins: [defineComponent(Mixin)],
data() {
return {
c: 2
calls.push('comp')
},
render() {
- return `${this.a}${this.b}${this.c}`
+ return `${this.a}${this.b}${this.c}${this.x}`
}
})
- expect(renderToString(h(Comp))).toBe(`1true2`)
- expect(calls).toEqual(['base', 'base2', 'comp'])
+ expect(renderToString(h(Comp))).toBe(`1true2mixin`)
+ expect(calls).toEqual(['base', 'mixin', 'comp'])
})
test('accessing setup() state from options', async () => {
}
}
- if (dataOptions) {
- if (__DEV__ && !isFunction(dataOptions)) {
- warn(
- `The data option must be a function. ` +
- `Plain object usage is no longer supported.`
- )
- }
-
- if (asMixin) {
- deferredData.push(dataOptions as DataFn)
- } else {
- resolveData(instance, dataOptions, publicThis)
- }
- }
if (!asMixin) {
if (deferredData.length) {
deferredData.forEach(dataFn => resolveData(instance, dataFn, publicThis))
}
+ if (dataOptions) {
+ resolveData(instance, dataOptions, publicThis)
+ }
if (__DEV__) {
const rawData = toRaw(instance.data)
for (const key in rawData) {
}
}
}
+ } else if (dataOptions) {
+ deferredData.push(dataOptions as DataFn)
}
if (computedOptions) {
dataFn: DataFn,
publicThis: ComponentPublicInstance
) {
+ if (__DEV__ && !isFunction(dataFn)) {
+ warn(
+ `The data option must be a function. ` +
+ `Plain object usage is no longer supported.`
+ )
+ }
const data = dataFn.call(publicThis, publicThis)
if (__DEV__ && isPromise(data)) {
warn(