vue.js 查看所有全局注册的组件,this.$options.components为空

im9ewurl  于 2023-01-02  发布在  Vue.js
关注(0)|答案(2)|浏览(278)

您好,我有一个新的Vue3应用程序使用Vite。我正在全局注册我的UserTextInput组件,但在我的所有组件this.$options.components是空的

import UserTextInput from "./components/defaultComponents/UserTextInput.vue";

const app = createApp(App);
app.component('UserTextInput', UserTextInput);
app.mount('#app');

在任何其他组件内部

mounted() {
    console.log(this.$options.components); // {} empty object
  },

我正在寻找一种方法来查看哪些组件已在全球注册。任何想法?

tv6aics1

tv6aics11#

你可以试试这个

import { getCurrentInstance } from 'vue';

getCurrentInstance().appContext.components // this will list all component registered globally
mspsb9vt

mspsb9vt2#

我在我的Vue 3应用程序中找到了列表:
应用程序示例应用程序上下文组件

相关问题