Nuxt 3 and PrimeVue bliss.
Follow this guide to quickly create a Nuxt 3 app with PrimeVue components for a fast and flexible front-end setup.
1st Mar 2023
Here’s a guide on setting up a simple test app with Nuxt 3 and PrimeVue:
Step 1: Create a New Nuxt 3 Project
Start by creating a new Nuxt 3 project using the following commands:
npx nuxi init nuxt3-primevue-app
cd nuxt3-primevue-app
npm install
Step 2: Install PrimeVue
Install PrimeVue and its required dependencies:
npm install primevue@^3.11.0 primeicons
Step 3: Set Up PrimeVue in Nuxt
To use PrimeVue in your app, you need to configure it in nuxt.config.ts
:
- Open
nuxt.config.ts
and add PrimeVue and PrimeIcons to the CSS and build settings.export default defineNuxtConfig({ css: [ 'primevue/resources/themes/saga-blue/theme.css', 'primevue/resources/primevue.min.css', 'primeicons/primeicons.css' ], build: { transpile: ['primevue'] } });
Step 4: Register PrimeVue Globally
You can create a PrimeVue plugin to register components globally:
- Create a file named
primevue.ts
in theplugins
directory (plugins/primevue.ts
). - Add the following code to initialize PrimeVue:
import PrimeVue from 'primevue/config'; import Button from 'primevue/button'; export default defineNuxtPlugin((nuxtApp) => { nuxtApp.vueApp.use(PrimeVue); nuxtApp.vueApp.component('Button', Button); });
Step 5: Use PrimeVue Components in Your Pages
You can now use PrimeVue components in your Nuxt app. For example, create a simple button in the pages/index.vue
file:
- Edit
pages/index.vue
:<template> <div class="p-4"> <h1>Welcome to Nuxt 3 with PrimeVue</h1> <Button label="Click Me" /> </div> </template>
Step 6: Run Your App
Run the app in development mode to test your setup:
npm run dev
That’s it! You now have a Nuxt 3 app running with PrimeVue components ready for use. You can experiment with different PrimeVue components to build a more complex app.