vue3中的getCurrentInstance


setup的執行時組件對象還沒有創建,此時不能使用this來訪問data/computed/methods/props
我們可以通過 getCurrentInstance這個函數來返回當前組件的實例對象,也就是當前vue這個實例對象

<template>
  <div>
  </div>
</template>
<script lang="ts">
import {defineComponent, getCurrentInstance} from 'vue';
export default defineComponent({
  setup () {
    const {proxy} = getCurrentInstance()
    console.log(proxy)
  } 
})
</script>
<style scoped>
</style>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM