查看“︁JavaScript/vue.js/getCurrentInstance”︁的源代码
来自康健生活
←
JavaScript/vue.js/getCurrentInstance
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 标题文本 == == 获取全局注册组件 == <syntaxhighlight lang="html"> <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> </syntaxhighlight> 另外一个思路 <syntaxhighlight lang="javascript"> // define a plugin const key = "__CURRENT_APP__" export const ProvideAppPlugin = { install(app, options) { app.provide(key, app) } } export function useCurrentApp() { return inject(key) } // when create app use the plugin createApp().use(ProvideAppPlugin) // get app instance in Component.vue const app = useCurrentApp() return () => h(app.version)</syntaxhighlight> {{Unknown|https://stackoverflow.com/questions/75446100/vue-3-get-current-application-instance}}
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
模板:Unknown
(
查看源代码
)
返回
JavaScript/vue.js/getCurrentInstance
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。