vue3中使用$forceUpdate

在vue2中直接

this.$forceUpdate()

在vue3中直接

import { getCurrentInstance } from "vue";
setup(){
//解构赋值 设置别名that  也可不写  :that  直接ctx
//ctx 得到普通对象
//proxy得到响应式对象
// 推荐使用proxy
      let {ctx:that, proxy} = getCurrentInstance()
    that.$forceUpdate()
}

在vue3+TS中直接

<script setup>
import { getCurrentInstance, ComponentInternalInstance } from 'vue';
setup(){
// ctx 得到普通对象
// proxy得到响应式对象
// 推荐使用proxy
    const { proxy } = getCurrentInstance() as ComponentInternalInstance
    proxy!.$forceUpdate()
}
</script>

参考:https://blog.csdn.net/qq_43291759?type=blog

猜你喜欢

转载自blog.csdn.net/weixin_46413834/article/details/129300348