JavaScript/vue.js/getCurrentInstance

来自康健生活
Kangkk​(留言 | 贡献)2025年4月16日 (三) 15:43的版本 (创建页面,内容为“== 标题文本 == == 获取全局注册组件 == <syntaxhighlight lang="jsx"> <template> <EchartsLinePanel v-if="options" :layerOptions="options" @update:layerOptions="handleUpdateOptions" /> </template> <script lang="ts" setup> import { defineAsyncComponent, getCurrentInstance, type ComponentInternalInstance } from 'vue' const { appContext } = <ComponentInternalInstance>getCurrentInstance() const EchartsLinePanel = defineAsyncComponent({…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

标题文本

获取全局注册组件

<template>
  <EchartsLinePanel
    v-if="options"
    :layerOptions="options"
    @update:layerOptions="handleUpdateOptions"
  />
</template>

<script lang="ts" setup>
import { defineAsyncComponent, getCurrentInstance, type ComponentInternalInstance } from 'vue'

const { appContext } = <ComponentInternalInstance>getCurrentInstance()

const EchartsLinePanel = defineAsyncComponent({
  loader: async () => {
    // 获得 athena-echarts-line 组件
    return appContext.components['athena-echarts-line']
  },
})
</script>