vue3中如何用vue2中的this

Posted 晚星@

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue3中如何用vue2中的this相关的知识,希望对你有一定的参考价值。

两种方案分别如下:

proxy = 》 this


<script  lang="ts">
import  getCurrentInstance, ComponentInternalInstance  from "vue";
export default function useCurrentInstance() 
  const  appContext  = getCurrentInstance() as ComponentInternalInstance;
  const proxy = appContext.config.globalProperties;
  return 
    proxy,
  ;

</script>
// @ts-ignore
<script  lang="ts">
import  getCurrentInstance, ComponentInternalInstance  from "vue";
export default function useCurrentInstance() 
  const  proxy  = getCurrentInstance() as ComponentInternalInstance;
  return 
    proxy,
  ;

</script>

以上是关于vue3中如何用vue2中的this的主要内容,如果未能解决你的问题,请参考以下文章