Skip to content

Commit

Permalink
fix(form): ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu committed Oct 12, 2023
1 parent 7cf58ff commit 9ee063c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/packages/__VUE/formitem/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</template>
<script lang="ts">
import { pxCheck } from '@/packages/utils/pxCheck';
import { computed, inject, provide, PropType, CSSProperties } from 'vue';
import { computed, inject, provide, PropType, CSSProperties, getCurrentInstance, onUnmounted } from 'vue';
import type { FormItemRule } from './types';
import { createComponent } from '@/packages/utils/create';
import Cell from '../cell/index.taro.vue';
Expand Down Expand Up @@ -77,6 +77,23 @@ export default create({
[Cell.name]: Cell
},
setup(props, { slots }) {
const useParent: any = () => {
const parent = inject('NutFormParent', null);
if (parent) {
// 获取子组件自己的实例
const instance = getCurrentInstance()!;
const { link, removeLink } = parent;
// @ts-ignore
link(instance);
onUnmounted(() => {
// @ts-ignore
removeLink(instance);
});
return { parent };
}
};
useParent();
const parent = inject('formErrorTip') as any;
provide('form', {
props
Expand Down
2 changes: 2 additions & 0 deletions src/packages/__VUE/formitem/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ export default create({
// 获取子组件自己的实例
const instance = getCurrentInstance()!;
const { link, removeLink } = parent;
// @ts-ignore
link(instance);
onUnmounted(() => {
// @ts-ignore
removeLink(instance);
});
return { parent };
Expand Down

0 comments on commit 9ee063c

Please sign in to comment.