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

项目开启页面缓存,但是相同页面的同组件内容会被覆盖 #3247

Closed
AidenYan97 opened this issue Nov 7, 2023 · 5 comments
Closed

Comments

@AidenYan97
Copy link

已有数据页面的Upload组件,已有文件数量为1
image
打开相同页面,但Upload组件已有文件数量为0
image
此时再切换回Uploa组件有数据的页面。Upload组件变为最近打开时组件的状态
image

也没有在文档上找到如何设置组件的key来区分组件缓存

@wangjue666
Copy link
Collaborator

看不明白你想表达什么,录制个视频吧

@AidenYan97
Copy link
Author

看不明白你想表达什么,录制个视频吧

就是a页面有上传组件,b页面也有上传组件,
但是b组件的上传组件加载数据后,有个文件B1,
我再切回a页面,a页面的上传组件内容就变成B1了。

@DesignHhuang
Copy link
Contributor

看不明白你想表达什么,录制个视频吧

就是a页面有上传组件,b页面也有上传组件, 但是b组件的上传组件加载数据后,有个文件B1, 我再切回a页面,a页面的上传组件内容就变成B1了。

你的组件是用<script setup>写的么?不是的话 KeepAlive 会根据组件的 name 选项进行匹配,所以组件如果想要条件性地被 KeepAlive 缓存,就必须显式声明一个 name 选项。
最好可以把你的代码贴出来,或者使用codespace。

@AidenYan97
Copy link
Author

AidenYan97 commented Nov 9, 2023

看不明白你想表达什么,录制个视频吧

就是a页面有上传组件,b页面也有上传组件, 但是b组件的上传组件加载数据后,有个文件B1, 我再切回a页面,a页面的上传组件内容就变成B1了。

你的组件是用<script setup>写的么?不是的话 KeepAlive 会根据组件的 name 选项进行匹配,所以组件如果想要条件性地被 KeepAlive 缓存,就必须显式声明一个 name 选项。 最好可以把你的代码贴出来,或者使用codespace。

嗯,使用的不是<script setup>写法,我也是接手的项目,他大概是这样写的

<template>
  <BasicForm @register="register" />
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { FormSchema } from '/@/components/Form/index';

export default defineComponent({
  name: 'InvoiceInWorkFlow',
  components: {
    BasicForm,
  },
  setup() {
    const invoiceInFormSchemas: FormSchema[] = [
      {
        field: 'PurchasingUnit',
        component: 'Input',
        label: '购货单位',
        required: true,
        itemProps: {
          labelCol: { class: 'label_w_xs' },
        },
        componentProps: {
          placeholder: '购货单位',
        },
        slot: 'PurchasingUnit',
      },
      {
        field: 'File',
        label: '附件',
        colProps: {
          lg: 24,
        },
        itemProps: {
          labelCol: { class: 'label_w_xs' },
        },
        component: 'Upload',
        componentProps: {
          maxSize: 10,
          api: '/api/upload',
        },
      },
    ];
    const [register, { validate, setFieldsValue: setValues, getFieldsValue, updateSchema }] = useForm({
      compact: true,
      baseColProps: {
        lg: 12,
        sm: 24,
      },
      schemas: invoiceInFormSchemas,
      showActionButtonGroup: false,
    });

    return {
      register,
    };
  },
});
</script>

他把Upload上传组件又套在了BasicForm组件里面,所以我想问问能不能给这个Upload上传组件单独声明一个唯一的key,这样打开相同得页面每个上传控件就不重复了。

@anncwb
Copy link
Collaborator

anncwb commented Apr 9, 2024

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@anncwb anncwb added the Stale label Apr 9, 2024
@anncwb anncwb closed this as completed Apr 17, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants