admin管理员组

文章数量:1530085

使用getCurrentInstance函数获得实例对象

const { proxy, ctx } = getCurrentInstance()

   推荐使用proxy

             因为用ctx用来代替this只适用于开发阶段,如果将项目打包放到生产服务器上运行,就会出错,ctx无法获取路由和全局挂载对象的

      

import { ref, computed, reactive, onMounted, getCurrentInstance } from 'vue'
 
const { proxy } = getCurrentInstance()

onMounted(() => {
    console.log(proxy)
  })

输出为

 

本文标签: 要用