新版vue 3.0的$forceUpdate的使用方法
2021-06-15 10:48:52
<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>