如何在vue3中设置forceUpdate?
当使用选项Api时,我可以使用forceUpdate.How的.$forceUpdate()在vue3的setup函数中执行相同的操作。
发布于 2021-05-11 14:51:05
<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>
完成
https://stackoverflow.com/questions/66529116
复制相似问题