如何在 vue3 设置中强制更新?
当使用Options Api时,我可以使用this.$forceUpdate()来强制更新。如何在vue3的setup函数中做同样的事情?
最佳答案
<script lang="ts">
import { defineComponent, getCurrentInstance } from "vue";
export default defineComponent({
setup() {
const { ctx: _this }: any = getCurrentInstance()
let arr = [1]
const handleClick = () => {
arr.push(2)
_this.$forceUpdate()
}
return {
arr
};
},
});
</script>
<template>
<div>
<div>{{arr}}</div>
<button @click="handleClick">add</button>
</div>
</template>
完毕
关于vue.js - 如何在 vue3 设置中强制更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66529116/