Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: useVbenVxeGrid在销毁/重建后表单依旧为上次数据 #4804

Closed
5 tasks done
imdap opened this issue Nov 4, 2024 · 2 comments
Closed
5 tasks done

Bug: useVbenVxeGrid在销毁/重建后表单依旧为上次数据 #4804

imdap opened this issue Nov 4, 2024 · 2 comments

Comments

@imdap
Copy link
Contributor

imdap commented Nov 4, 2024

Version

Vben Admin V5

Describe the bug?

useVbenVxeGrid在销毁/重建后表单依旧为上次数据

影响功能: 在modal/drawer中的表格 第二次打开无法查询数据(依旧为上一次表单数据)及使用v-if切换

Reproduction

<script>
const init = ref(true);
async function mockLoadTable() {
  init.value = false;
  await nextTick();
  init.value = true;
}
</script>

<template>
  <Page auto-content-height>
    <Button @click="mockLoadTable">模拟重新加载</Button>
    <Grid v-if="init" />
    <ModalTable />
  </Page>
</template>

使用v-if来模拟组件加载/卸载
第一次点击查询
image
模拟加载后再次点击依旧为上一次表单的值
image

useVbenVxeGrid

const Grid = defineComponent(
    (props: VxeGridProps, { attrs, slots }) => {
      onBeforeUnmount(() => {
        api.unmount();
      });
      api.setState({ ...props, ...attrs });

      console.log('表单的值:', extendedApi.formApi.form?.values);

      return () => h(VxeGrid, { ...props, ...attrs, api: extendedApi }, slots);
    },
    {
      inheritAttrs: false,
      name: 'VbenVxeGrid',
    },
  );

image

System Info

win11

Relevant log output

No response

Validations

@imdap
Copy link
Contributor Author

imdap commented Nov 4, 2024

相关issue
#4752
#4785

@imdap
Copy link
Contributor Author

imdap commented Nov 4, 2024

组件销毁重建 闭包引用的外部的extendedApi一直为第一次初始化的值

export function useVbenVxeGrid(options: VxeGridProps) {
  // const IS_REACTIVE = isReactive(options);
  const api = new VxeGridApi(options);
  const extendedApi: ExtendedVxeGridApi = api as ExtendedVxeGridApi;
  extendedApi.useStore = (selector) => {
    return useStore(api.store, selector);
  };

  const Grid = defineComponent(
    (props: VxeGridProps, { attrs, slots }) => {
      onBeforeUnmount(() => {
        api.unmount();
      });
      api.setState({ ...props, ...attrs });
// 这里的api不论组件怎么销毁重建依旧为第一次的值
      return () => h(VxeGrid, { ...props, ...attrs, api: extendedApi }, slots);
    },

@imdap imdap closed this as completed Nov 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant