Technology Sharing

The drawer component in Vue3 cannot re-display data

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

When the drawer is not used, the data can be displayed normally, and the value can be transmitted normally when clicking the detail id. However, after using the drawer component, it is found that the detail function will only be called once. No matter which information is clicked, the information will not be refreshed and will always be the first information. However, the id is refreshed successfully. Later, it is found that v-if is not added to determine the open value of the drawer. If you have the same problem, you can refer to the following code.

Drawer component:

  1. <!-- 表单弹窗:详情 -->
  2. <el-drawer
  3. v-model="drawer"
  4. title="详情"
  5. :direction="direction"
  6. v-if="drawer"
  7. size ="71%"
  8. class="drawer"
  9. destory-on-close
  10. >
  11. <DetailForm ref="detailRef" :detailId="detailId"/>
  12. </el-drawer>

import:

  1. import type { DrawerProps } from 'element-plus'
  2. import { ref } from 'vue';
  3. import DetailForm from '@/views/teach/coursemanagePlus/Index.vue'

How to view details:

  1. /** 查看详情 */
  2. const detailRef = ref()
  3. const drawer = ref(false)
  4. const detailId = ref()
  5. const details = (type: string, id?: number) => {
  6. drawer.value=true
  7. detailId.value=id
  8. }

That's it.

Welcome everyone to criticize and correct me, or if you have better methods, let’s communicate and learn together!