在vue3使用$forceUpdate的方法
如果真的很需要在vue3中使用forceUpdate,同时又想使用 <script lang="ts" setup>的写法,那么可以这样写:
<template>
<button @click="handleClick">按钮</button>
</template>
<style scoped lang="less"></style>
<script lang="ts" setup>
import { getCurrentInstance } from "vue";
const {
proxy: { $forceUpdate },
}: any = getCurrentInstance();
function handleClick() {
$forceUpdate();
console.log($forceUpdate, "bingo!");
}
</script>