如何在 vue3 设置中强制更新?
当使用Options Api时,我可以使用this.$forceUpdate()来强制更新。如何在vue3的setup函数中做同样的事情?
小智 4
<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>Run Code Online (Sandbox Code Playgroud)
<template>
<div>
<div>{{arr}}</div>
<button @click="handleClick">add</button>
</div>
</template>Run Code Online (Sandbox Code Playgroud)
完毕
| 归档时间: |
|
| 查看次数: |
1308 次 |
| 最近记录: |