如何在普通js文件中获取vue3实例 #7945
-
如何在普通js文件中获取vue3实例,主要是js文件是各个功能模块,需要在普通js文件里获取thisvue实例。有办法获取到吗? main.js导出vue实例,普通js文件导入这种方式无效。 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
-
import { getCurrentInstance } from ‘vue’ |
Beta Was this translation helpful? Give feedback.
-
你去看源码就知道了
…---原始邮件---
发件人: ***@***.***>
发送时间: 2023年4月6日(周四) 下午4:25
收件人: ***@***.***>;
抄送: ***@***.******@***.***>;
主题: Re: [vuejs/core] 如何在普通js文件中获取vue3实例 (Discussion #7945)
你好,这个函数的api通过vue官网并未找到,应该不是官方支持的行为吧。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
https://v3.ru.vuejs.org/api/composition-api.html#getcurrentinstance |
Beta Was this translation helpful? Give feedback.
import { getCurrentInstance } from ‘vue’
const instance = getCurrentInstance()