获取当前组件实例
注意:只能在同步的 setup 函数顶部使用 并且无法在逻辑判断,异步执行中使用
import { getCurrentInstance } from '@zhengxs/composition-api' export default { setup() { // ✅ 正确用法 // 如果需要可以在顶部保存 const vm = getCurrentInstance() console.log(vm) if (flag) // ❌ 错误用法 console.log(getCurrentInstance()) } onBeforeMount(() => { // ❌ 错误用法 console.log(getCurrentInstance()) }) } }
组件实例
创建响应式对象 Vue.observable 的别名
原始值
响应式对象
获取当前组件实例
注意:只能在同步的 setup 函数顶部使用 并且无法在逻辑判断,异步执行中使用