Undefined property '$primevue' accessed during rendering
P粉476547076
P粉476547076 2023-08-25 16:17:16
0
1
567

Cases and Questions

I am working on a private project using Vue.js and I encountered the following error when I tried to use FileUploadPrimeVue code>Occurs when component:

[Vue warn]: Property '$primevue' was accessed during rendering, but the property is undefined on the instance. 

Trying to use FileUpload in my component:

 

The error only occurs when I try to use FileUpload, if I remove it the component works fine. FileUpload and PrimeVue are both imported in main.js as they should:

import {createApp} from 'vue' import router from "./router"; import store from "./store"; import PrimeVue from "primevue/config"; import PrimeIcons from "primevue/config"; import App from "./App"; const app = createApp(App); app.use( router, PrimeVue, PrimeIcons, store ) import 'primevue/resources/primevue.min.css' import 'primeflex/primeflex.css' import 'primeicons/primeicons.css' import 'primevue/resources/themes/bootstrap4-dark-purple/theme.css' import Card from "primevue/card"; import Menubar from "primevue/menubar"; import FileUpload from "primevue/fileupload"; app.component('Card', Card) app.component('Menubar', Menubar) app.component('FileUpload', FileUpload) app.mount('#app') 

What I tried

I searched for this issue, but the only exact match for this error was an old closed issue on GitHub for the Calendar component: Issue #808.This issue is caused by breaking changes in the new PrimeVue API. This shouldn't be my case since it was introduced in V3.1 and I'm using V3.7.

If the version is the problem, I tested different versions of PrimeVue, such as 3.1, 3.2, 3.3, but the error still exists. Therefore, the actual dependencies are still up to date:

"primevue": "^3.7.0"

Maybe a solution already exists on SO or Google, but either my English is too poor to understand, or I'm not familiar enough with Vue.js to understand the problem.

Thanks in advance!

P粉476547076
P粉476547076

reply all (1)
P粉611456309

You are usingapp.use()incorrectly:

app.use( router, PrimeVue, PrimeIcons, store )

app.use()Only accepts two parameters:

  • First parameter:Vue plug-in
  • Second parameter:Plug-in options

Also,PrimeIconsis not a plugin, so it should not be passed toapp.use().

solution

Pass each plugin individually toapp.use():

app.use(router) .use(PrimeVue) //.use(PrimeIcons) // 不是一个插件 .use(store)
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!