赞
踩
const { proxy, ctx } = getCurrentInstance()
因为用ctx用来代替this只适用于开发阶段,如果将项目打包放到生产服务器上运行,就会出错,ctx无法获取路由和全局挂载对象的
- import { ref, computed, reactive, onMounted, getCurrentInstance } from 'vue'
-
- const { proxy } = getCurrentInstance()
-
- onMounted(() => {
- console.log(proxy)
- })
输出为
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。