parent
e4f09c1419
commit
7a1a782642
@ -251,6 +251,7 @@ describe('api: options', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('provide/inject', () => {
|
test('provide/inject', () => {
|
||||||
|
const symbolKey = Symbol()
|
||||||
const Root = defineComponent({
|
const Root = defineComponent({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -259,7 +260,8 @@ describe('api: options', () => {
|
|||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
return {
|
return {
|
||||||
a: this.a
|
a: this.a,
|
||||||
|
[symbolKey]: 2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
@ -271,7 +273,9 @@ describe('api: options', () => {
|
|||||||
h(ChildE),
|
h(ChildE),
|
||||||
h(ChildF),
|
h(ChildF),
|
||||||
h(ChildG),
|
h(ChildG),
|
||||||
h(ChildH)
|
h(ChildH),
|
||||||
|
h(ChildI),
|
||||||
|
h(ChildJ)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -321,7 +325,15 @@ describe('api: options', () => {
|
|||||||
default: () => 5
|
default: () => 5
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
expect(renderToString(h(Root))).toBe(`11112345`)
|
const ChildI = defineChild({
|
||||||
|
b: symbolKey
|
||||||
|
})
|
||||||
|
const ChildJ = defineChild({
|
||||||
|
b: {
|
||||||
|
from: symbolKey
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(renderToString(h(Root))).toBe(`1111234522`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('provide accessing data in extends', () => {
|
test('provide accessing data in extends', () => {
|
||||||
|
@ -5,7 +5,7 @@ import { warn } from './warning'
|
|||||||
|
|
||||||
export interface InjectionKey<T> extends Symbol {}
|
export interface InjectionKey<T> extends Symbol {}
|
||||||
|
|
||||||
export function provide<T>(key: InjectionKey<T> | string, value: T) {
|
export function provide<T>(key: InjectionKey<T> | string | number, value: T) {
|
||||||
if (!currentInstance) {
|
if (!currentInstance) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
warn(`provide() can only be used inside setup().`)
|
warn(`provide() can only be used inside setup().`)
|
||||||
|
@ -667,9 +667,9 @@ export function applyOptions(
|
|||||||
const provides = isFunction(provideOptions)
|
const provides = isFunction(provideOptions)
|
||||||
? provideOptions.call(publicThis)
|
? provideOptions.call(publicThis)
|
||||||
: provideOptions
|
: provideOptions
|
||||||
for (const key in provides) {
|
Reflect.ownKeys(provides).forEach(key => {
|
||||||
provide(key, provides[key])
|
provide(key, provides[key])
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user