PrimeVue

Next Generation Vue UI Component Library

README

License: MIT npm version Actions CI Discord Chat
PrimeVue Hero

PrimeVue


PrimeVue is a rich set of open source UI Components for Vue. See PrimeVue homepage for live showcase and documentation.

Download


PrimeVue is available at npm, if you have an existing application run the following command to download it to your project.

  1. ````
  2. npm install primevue@^3 --save
  3. npm install primeicons --save
  4. ````

or

  1. ```
  2. yarn add primevue
  3. yarn add primeicons
  4. ```

Next step is setting up PrimeVue configuration.

  1. ``` js
  2. import {createApp} from 'vue';
  3. import App from './App.vue';
  4. import PrimeVue from 'primevue/config';
  5. const app = createApp(App);

  6. app.use(PrimeVue);
  7. ```

Import


Module


  1. ``` js
  2. import {createApp} from 'vue';
  3. import App from './App.vue';
  4. import PrimeVue from 'primevue/config';
  5. import Dialog from 'primevue/dialog';
  6. const app = createApp(App);

  7. app.use(PrimeVue);

  8. app.component('Dialog', Dialog);
  9. ```

Finally you'll be able to utilize the component in your application. See the Styles section to apply styling.

  1. ```vue
  2. <Dialog></Dialog>
  3. ```

CDN


  1. ``` js
  2. <script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>/script>
  3. <script src="https://unpkg.com/primevue@^3/multiselect/multiselect.min.js"></script>
  4. ```

Single File Components


SFC files are available in the npm distribution and if you'd like to use SFCs directly, add /sfc as a suffix when referencing an import path. This will instruct your bundler to process the *.vue files in your local build instead of using the compiled output. One use case for this approach is optimizing for SSR by removing whitespaces.

  1. ``` js
  2. import Dialog from 'primevue/dialog/sfc';
  3. ```

Script Tag


Other alternative is utilizing the components directly within the browser with the iife build. Note that PrimeVue does not provide a umd build.

  1. ``` js
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>PrimeVue Demo</title>
  6.         <link href="https://unpkg.com/primevue/resources/themes/lara-light-indigo/theme.css" rel="stylesheet">
  7.         <link href="https://unpkg.com/primevue/resources/primevue.min.css" rel="stylesheet">
  8.         <link href="https://unpkg.com/primeicons/primeicons.css" rel="stylesheet">
  9. <script src="https://unpkg.com/vue@next"></script>
  10.         <script src="https://unpkg.com/primevue^3/core/core.min.js"></script>
  11.         <script src="https://unpkg.com/primevue^3/slider/slider.min.js"></script>
  12.     </head>
  13. <body>
  14.         <div id="app">
  15.             <p-slider v-model="val"></p-slider>
  16.             <h6>{{val}}</h6>
  17.         </div>
  18. <script>
  19.             const {createApp, ref} = Vue;

  20.             const App = {
  21.                 setup() {
  22.                     const val = ref(null);

  23.                     return {
  24.                         val
  25.                     };
  26.                 },
  27.                 components: {
  28.                     'p-slider': primevue.slider
  29.                 }
  30.             };

  31.             createApp(App).use(primevue.config.default).mount("#app");
  32.         </script>
  33.     </body>
  34. </html>
  35. ```

Styles


The css dependencies are as follows, note that you may change the theme with another one of your choice.

  1. ```css
  2. primevue/resources/themes/saga-blue/theme.css       //theme
  3. primevue/resources/primevue.min.css                 //core css
  4. primeicons/primeicons.css                           //icons
  5. ```

If you are using a bundler such as webpack with a css loader you may also import them to your main application component.

  1. ``` js
  2. import 'primevue/resources/themes/lara-light-indigo/theme.css';
  3. import 'primevue/resources/primevue.min.css';
  4. import 'primeicons/primeicons.css';
  5. ```

Nuxt Integration


Nuxt 3 is currently in beta and an official module is planned after the final release. At the moment, PrimeVue can easily be used with Nuxt 3 using a custom plugin.

nuxt.config.js

Open the nuxt configuration file and add the css dependencies.

  1. ``` js
  2. import { defineNuxtConfig } from 'nuxt3';

  3. export default defineNuxtConfig({
  4.     css: [
  5.         'primevue/resources/themes/saga-blue/theme.css',
  6.         'primevue/resources/primevue.css',
  7.         'primeicons/primeicons.css'
  8.     ],
  9.     build: {
  10.         transpile: ['primevue']
  11.     }
  12. })
  13. ```

primevue.js

Create a file like primevue.js under the plugins directory for the configuration.

  1. ``` js
  2. import { defineNuxtPlugin } from "#app";
  3. import PrimeVue from "primevue/config";
  4. import Button from "primevue/button";

  5. export default defineNuxtPlugin((nuxtApp) => {
  6.     nuxtApp.vueApp.use(PrimeVue, {ripple: true});
  7.     nuxtApp.vueApp.component('Button', Button);
  8.     //other components that you need
  9. });
  10. ```

Configuration


Dependencies


PrimeVue components are not wrappers and implemented natively with the Vue APIs. There are some exceptions having 3rd party dependencies such as Quill for Editor.

In addition, components require PrimeIcons library for icons.

  1. ``` js
  2. dependencies: {
  3.     "vue": "^3.0.0",
  4.     "primeicons": "^6.0.0"
  5. }
  6. ```

Prop Cases


Component prop names are described as camel case throughout the documentation however camel-case is also fully supported. Events on the other hand should always be camel-case.

  1. ```vue
  2. <Dialog :showHeader="false"></Dialog>
  3. <Dialog :show-header="false"></Dialog>
  4. ```

Ripple


Ripple is an optional animation for the supported components such as buttons. It is disabled by default and needs to be enabled at your app's entry file (e.g. main.js) during the PrimeVue setup.

  1. ``` js
  2. import {createApp} from 'vue';
  3. import PrimeVue from 'primevue/config';
  4. const app = createApp(App);

  5. app.use(PrimeVue, {ripple: true});
  6. ```

Outlined vs Filled Input Styles


Input fields come in two styles, default is outlined with borders around the field whereas filled alternative adds a background color to the field. Applying p-input-filled to an ancestor of an input enables the filled style. If you prefer to use filled inputs in the entire application, use a global container such as the document body or the application element to apply the style class. Note that in case you add it to the application element, components that are teleported to the document body such as Dialog will not be able to display filled inputs as they are not a descendant of the application root element in the DOM tree, to resolve this case set inputStyle to 'filled' at PrimeVue configuration as well.

  1. ``` js
  2. import {createApp} from 'vue';
  3. import PrimeVue from 'primevue/config';
  4. const app = createApp(App);

  5. app.use(PrimeVue, {inputStyle: 'filled'});
  6. ```

ZIndex Layering


ZIndexes are managed automatically to make sure layering of overlay components work seamlessly when combining multiple components. Still there may be cases where you'd like to configure the configure default values such as a custom layout where header section is fixed. In a case like this, dropdown needs to be displayed below the application header but a modal dialog should be displayed above. PrimeVue configuration offers the zIndex property to customize the default values for components categories. Default values are described below and can be customized when setting up PrimeVue.

  1. ``` js
  2. import {createApp} from 'vue';
  3. import PrimeVue from 'primevue/config';
  4. const app = createApp(App);

  5. app.use(PrimeVue, {
  6.     zIndex: {
  7.         modal: 1100,        //dialog, sidebar
  8.         overlay: 1000,      //dropdown, overlaypanel
  9.         menu: 1000,         //overlay menus
  10.         tooltip: 1100       //tooltip
  11.     }
  12. });
  13. ```

Locale


PrimeVue provides a Locale API to support i18n and l7n, visit the Locale documentation for more information.

Quickstart with Create Vue


An example application based on Create Vue is available at github.

Quickstart with Create Vue TypeScrript


An sample application based on Create Vue is available at github.

Quickstart with Vue CLI


An example application based on Vue CLI is available at github.

Quickstart with Vite


A starter application is also provided for Vite users.

Quickstart with Nuxt


A sample application is created for Nuxt 3 users.

Quickstart with TypeScript


Typescript is fully supported as type definition files are provided in the npm package of PrimeVue. A sample typescript-primevue application with Vue CLI is available as at github.