vue3使用getCurrentInstance的一些记录

4,176 阅读1分钟

vue3使用getCurrentInstance的一些记录

  • 如果需要获取当前组件实例,使用{proxy} = getCurrentInstance() 获取到proxy代理对象。
  • proxy可以获取到通过app.config.globalProperties.something定到全局的方法、变量。
  • 也可以通过proxy获取到当前组件的refs进行处理。
    app.config.globalProperties.$https = new Https(Interceptors)
    const {proxy} = getCurrentInstance()
    const http = proxy.$https //获取到请求方法