Skip to content

Commit

Permalink
fix: provideservice correct value
Browse files Browse the repository at this point in the history
  • Loading branch information
agileago committed Nov 13, 2024
1 parent 91b32a8 commit eaaf9bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion example/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,40 @@ import {
Component,
type ComponentProps,
Hook,
injectService,
Link,
mergeRefs,
Mut,
provideService,
VueComponent,
} from 'vue3-oop'
import { createApp, shallowRef } from 'vue'
import { createApp, defineComponent, ref, shallowRef } from 'vue'
import { ConfigProvider, Layout, Menu } from 'ant-design-vue'
import { RouterLink, RouterView } from 'vue-router'
import { RouterStartService } from './router'
import { routes } from './router/routes'
import zhCN from 'ant-design-vue/lib/locale/zh_CN'
import { setup } from './setup'

class AService {
height = ref(0)
}

const A1 = defineComponent(() => {
provideService(new AService())
return () => (
<div>
<A2></A2>
</div>
)
})

const A2 = defineComponent(() => {
const a = injectService(AService)
console.log(11111, a)
return () => <div>111 {a.height.value}</div>
})

interface ChildProps {
value?: string
'onUpdate:value'?: (val: string) => any
Expand Down Expand Up @@ -101,6 +122,7 @@ class App extends VueComponent {
</Layout.Sider>
<Layout.Content>
<RouterView></RouterView>
<A1></A1>
</Layout.Content>
</Layout>
</ConfigProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/di/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function provideService<T extends Constructable>(...service: T[]) {
// @ts-ignore
injector.keyIds[index] = provider.key.id
// @ts-ignore
injector.objs[index] = provider[i]
injector.objs[index] = service[i]
})
return injector
}
Expand Down

0 comments on commit eaaf9bc

Please sign in to comment.