當(dāng)前位置:首頁(yè) > IT技術(shù) > 其他 > 正文

Vue3中如何使用this
2022-09-06 22:51:21

vue3提供了getCurrentInstance ,通過(guò)這個(gè)屬性,直接使用ctx是錯(cuò)誤的,需要找到全局屬性globalProperties

import { getCurrentInstance } from 'vue'
const instance = getCurrentInstance()
const _this= instance.appContext.config.globalProperties

這里的_this就相當(dāng)于vue2里的this

方案2:

const { proxy } = getCurrentInstance()

使用proxy線上也不會(huì)出現(xiàn)問(wèn)題

本文摘自 :https://www.cnblogs.com/

開(kāi)通會(huì)員,享受整站包年服務(wù)立即開(kāi)通 >