简体   繁体   English

Vue-TypeScript 应用程序类型错误:无法读取未定义的属性(读取“配置”)

[英]Vue-TypeScript Application TypeError: Cannot read properties of undefined (reading 'config')

I am new to Vue 3 & TypeScript and using PrimeVue.我是 Vue 3 和 TypeScript 的新手,并且正在使用 PrimeVue。 I am trying to learn by creating a simple todo app.我正在尝试通过创建一个简单的待办事项应用程序来学习。 I run into an error that says我遇到了一个错误,上面写着

Uncaught TypeError: Cannot read properties of undefined (reading 'config')
at Proxy.containerClass (menu.esm.js:306:50)
at ReactiveEffect.run (reactivity.esm-bundler.js:185:25)
at get value [as value] (reactivity.esm-bundler.js:1144:39)
at Object.get [as containerClass] (runtime-core.esm-bundler.js:3427:30)
at menu.esm.js:346:33
at Proxy.renderFnWithContext (runtime-core.esm-bundler.js:853:21)
at Proxy.<anonymous> (runtime-core.esm-bundler.js:1947:78)
at renderComponentRoot (runtime-core.esm-bundler.js:896:44)
at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5580:57)
at ReactiveEffect.run (reactivity.esm-bundler.js:185:25)

I'm not sure what it means.我不确定这意味着什么。 I searched through the code for config but still didn't understand what the problem is.我搜索了配置代码,但仍然不明白问题所在。 Here's a snippet if it's helpful.这是一个片段,如果它有帮助的话。

 <script setup lang="ts">
 import { ref } from 'vue';
 import Menubar from 'primevue/menubar'
 import Menu from 'primevue/menu';

    const items = ref([
        {  
            items: [{
                label: 'Search',
                icon: 'pi pi-search',
                uri: './LeftNavigation.vue'
            },
            {
                label: 'View Completed',
                icon: 'pi pi-check-square', 
                uri: ''
            },
            {
                label: 'Delete',
                icon: 'pi pi-trash',
                uri: ''
            },
            {
                label: 'View Archived',
                icon: 'pi pi-cloud-upload',
                uri: ''
            },
            {
                label: 'View All',
                icon: 'pi pi-list',
                uri: ''
            },                                                                
        ]},
    ]);
   </script>

   <template>
     <div style="background-color:brown;width:50px">
       <Menu :model="items" />
     </div>
   </template>

   <style lang="scss" scoped>

   </style>

I think you have to import it like this:我认为你必须像这样导入它:

 <script setup lang="ts">
 import Menu from 'primevue/menu/sfc';

https://www.primefaces.org/primevue/setup https://www.primefaces.org/primevue/setup

You've mounted the app before installing the PrimeVue plugin:在安装 PrimeVue 插件之前,您已经安装了应用程序

// main.ts
⋮
const app = createApp(App)
app.mount('#app') 👈
app.use(PrimeVue)
app.use(DialogService)

That leads to the error you encountered when the PrimeVue component attempts to find its config, which is supposed to be setup by the plugin.这会导致您在 PrimeVue 组件尝试查找其配置时遇到的错误,该配置应该由插件设置。

Solution解决方案

Mount the component as the last initialization step:挂载组件作为最后一个初始化步骤:

// main.ts
⋮
const app = createApp(App)
app.use(PrimeVue)
app.use(DialogService)
app.mount('#app') 👈

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue 3 + Vue Router 4:TypeError:无法读取未定义的属性(读取“推送”) - Vue 3 + Vue Router 4: TypeError: Cannot read properties of undefined (reading 'push') 未捕获的类型错误:无法在 vue 3 中读取未定义的属性(读取“modelValue”) - uncaught TypeError: Cannot read properties of undefined (reading 'modelValue') in vue 3 TypeError:无法读取未定义的属性(读取“原型”)React Typescript + Express - TypeError: Cannot read properties of undefined (reading 'prototype') React Typescript + Express `TypeError:无法读取未定义的属性(阅读`<typescript_attributes> ')`</typescript_attributes> - `TypeError: Cannot read properties of undefined (reading `<typescript_attributes>')` ... Vue-TypeScript 应用程序中的 mapActions 导致错误 - …mapActions in Vue-TypeScript application cause error 类型错误:无法读取未定义的属性(读取“id”) - TypeError: Cannot read properties of undefined (reading 'id') TypeError:无法读取未定义的属性(读取“addEventListener”) - TypeError: Cannot read properties of undefined (reading 'addEventListener') TypeError:无法读取未定义的属性(读取“getDeep”) - TypeError: Cannot read properties of undefined (reading 'getDeep') TypeError:无法读取未定义的属性(正在读取“pageNumber”) - TypeError: Cannot read properties of undefined (reading 'pageNumber') TypeError - 无法读取未定义的属性(读取“名称”) - TypeError - Cannot read properties of undefined (reading 'name')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM