vue3重新渲染元件的方式

Mao

Vue3 rerender a component

  1. v-if
    透過v-if的判斷,將組件移除後,重新創立,掛載。

  2. 鍵值改變驅動Key-Changing
    只需要在component上,綁定key值,就可以透過key值的改動,觸發component的更新

1
2
3
<template>
<component :key="componentKey" />
</template>
1
2
3
4
5
6
import { ref } from 'vue';
const componentKey = ref(0);

const Rerender = () => {
componentKey.value += 1;
};
  • 標題: vue3重新渲染元件的方式
  • 作者: Mao
  • 撰寫于: 2023-08-05 03:24:00
  • 更新于: 2023-08-05 03:32:57
  • 連結: https://mao0507.github.io/2023/08/05/vue/vue3重新渲染元件的方式/
  • 版權宣告: 本作品采用 CC BY-NC-SA 4.0 進行許可。
 留言
此頁目錄
vue3重新渲染元件的方式