})
test('provide/inject', () => {
+ const symbolKey = Symbol()
const Root = defineComponent({
data() {
return {
},
provide() {
return {
- a: this.a
+ a: this.a,
+ [symbolKey]: 2
}
},
render() {
h(ChildE),
h(ChildF),
h(ChildG),
- h(ChildH)
+ h(ChildH),
+ h(ChildI),
+ h(ChildJ)
]
}
})
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', () => {
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 (__DEV__) {
warn(`provide() can only be used inside setup().`)
const provides = isFunction(provideOptions)
? provideOptions.call(publicThis)
: provideOptions
- for (const key in provides) {
+ Reflect.ownKeys(provides).forEach(key => {
provide(key, provides[key])
- }
+ })
})
}