mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 代码优化
This commit is contained in:
@ -7,7 +7,7 @@ interface DemoContext {
|
||||
setCounts: (count: number) => void;
|
||||
}
|
||||
|
||||
const { useProvide: useDemoProvider, useInject: useDemoInject } = useContext<DemoContext>();
|
||||
const { useProvide: useDemoProvide, useInject: useDemoInject } = useContext<DemoContext>();
|
||||
|
||||
export function useDemoContext() {
|
||||
const counts = ref(0);
|
||||
@ -21,12 +21,12 @@ export function useDemoContext() {
|
||||
setCounts
|
||||
};
|
||||
|
||||
function useProvider() {
|
||||
useDemoProvider(demoContext);
|
||||
function useProvide() {
|
||||
useDemoProvide(demoContext);
|
||||
}
|
||||
|
||||
return {
|
||||
useProvider,
|
||||
useProvide,
|
||||
useInject: useDemoInject
|
||||
};
|
||||
}
|
||||
@ -34,8 +34,8 @@ export function useDemoContext() {
|
||||
// 示例用法: A.vue为父组件, B.vue为子孙组件 C.vue为子孙组件
|
||||
// A.vue
|
||||
// import { useDemoContext } from '@/context';
|
||||
// const { useProvider } = useDemoContext();
|
||||
// useProvider();
|
||||
// const { useProvide } = useDemoContext();
|
||||
// useProvide();
|
||||
|
||||
// B.vue 和 C.vue : 共享状态 counts
|
||||
// import { useDemoContext } from '@/context';
|
||||
|
Reference in New Issue
Block a user