Verwendung von $forceUpdate in vue3

Direkt in vue2

this.$forceUpdate()

Direkt in vue3

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

Direkt in vue3+TS

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

Referenz: https://blog.csdn.net/qq_43291759?type=blog

Je suppose que tu aimes

Origine blog.csdn.net/weixin_46413834/article/details/129300348
conseillé
Classement