Vue3中使用const {proxy} = getCurrentInstance()代理标错Uncaught (in promise) TypeError: 'set' on proxy: trap returned falsish for property

修改导入方式

//  方式二,此方法在开发环境以及生产环境下都能放到组件上下文对象(推荐)
const {proxy}  = getCurrentInstance();

改为

//  方式二,此方法在开发环境以及生产环境下都能放到组件上下文对象(推荐)
const proxy  = getCurrentInstance();

使用:
//
onMounted(async () => {
  if (proxy) {
      //挂载自己的函数函数,在其他地方进行使用
    proxy.onDownloadProgress = onDownloadProgress;
  }
})

如果要使用全局的挂载的组件:
// 获取当前组件实例
const instance = getCurrentInstance();
instance.proxy.$modal.msgSuccess(123)
posted @ 2024-07-12 09:38  成强  阅读(10)  评论(0编辑  收藏  举报