What is primevue?
PrimeVue is a comprehensive UI component library for Vue.js that provides a wide range of components to build modern, responsive, and feature-rich web applications. It includes components for forms, data display, overlays, menus, charts, messages, and more.
What are primevue's main functionalities?
Form Components
PrimeVue provides a variety of form components such as input fields, buttons, checkboxes, and more. This example demonstrates a simple form with an input field and a submit button.
<template>
<div>
<InputText v-model="value" placeholder="Enter your name" />
<Button label="Submit" @click="submitForm" />
</div>
</template>
<script>
import { InputText } from 'primevue/inputtext';
import { Button } from 'primevue/button';
export default {
components: { InputText, Button },
data() {
return {
value: ''
};
},
methods: {
submitForm() {
console.log(this.value);
}
}
};
</script>
Data Display
PrimeVue offers powerful data display components like DataTable, which can be used to display and manipulate tabular data. This example shows a simple data table with product names and prices.
<template>
<DataTable :value="products">
<Column field="name" header="Name"></Column>
<Column field="price" header="Price"></Column>
</DataTable>
</template>
<script>
import { DataTable } from 'primevue/datatable';
import { Column } from 'primevue/column';
export default {
components: { DataTable, Column },
data() {
return {
products: [
{ name: 'Product 1', price: 100 },
{ name: 'Product 2', price: 200 }
]
};
}
};
</script>
Overlay Components
PrimeVue includes overlay components like Dialog, Tooltip, and OverlayPanel. This example demonstrates a simple dialog that can be shown or hidden by clicking a button.
<template>
<div>
<Button label="Show Dialog" @click="showDialog = true" />
<Dialog v-model:visible="showDialog" header="Dialog Header">
<p>Dialog Content</p>
</Dialog>
</div>
</template>
<script>
import { Button } from 'primevue/button';
import { Dialog } from 'primevue/dialog';
export default {
components: { Button, Dialog },
data() {
return {
showDialog: false
};
}
};
</script>
Menu Components
PrimeVue provides various menu components like Menubar, Menu, and ContextMenu. This example shows a simple menubar with 'Home' and 'About' menu items.
<template>
<div>
<Menubar :model="items" />
</div>
</template>
<script>
import { Menubar } from 'primevue/menubar';
export default {
components: { Menubar },
data() {
return {
items: [
{ label: 'Home', icon: 'pi pi-fw pi-home' },
{ label: 'About', icon: 'pi pi-fw pi-info' }
]
};
}
};
</script>
Chart Components
PrimeVue includes chart components based on Chart.js. This example demonstrates a simple bar chart displaying sales data for three months.
<template>
<Chart type="bar" :data="chartData" />
</template>
<script>
import { Chart } from 'primevue/chart';
export default {
components: { Chart },
data() {
return {
chartData: {
labels: ['January', 'February', 'March'],
datasets: [
{
label: 'Sales',
backgroundColor: '#42A5F5',
data: [65, 59, 80]
}
]
};
};
}
};
</script>
Other packages similar to primevue
vuetify
Vuetify is a popular Vue.js component library that follows the Material Design guidelines. It offers a wide range of components and features similar to PrimeVue, but with a focus on Material Design aesthetics.
element-plus
Element Plus is a Vue 3 UI library that provides a comprehensive set of components for building web applications. It is known for its ease of use and extensive documentation, making it a strong alternative to PrimeVue.
bootstrap-vue
BootstrapVue provides Vue.js components and directives based on Bootstrap 4. It combines the power of Bootstrap with the flexibility of Vue, offering a wide range of components similar to PrimeVue.
ant-design-vue
Ant Design Vue is a Vue.js implementation of the Ant Design system. It offers a rich set of high-quality components and follows the Ant Design guidelines, making it a strong competitor to PrimeVue.
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.
# Using npm
npm install primevue
# Using yarn
yarn add primevue
# Using pnpm
pnpm add primevue
Plugin
PrimeVue plugin is required to be installed with the use function to set up the default configuration.
import { createApp } from 'vue';
import PrimeVue from 'primevue/config';
const app = createApp(App);
app.use(PrimeVue);
Theming
PrimeVue has two theming has modes; styled or unstyled.
Styled Mode
Styled mode is based on pre-skinned components with opinionated themes like Material, Bootstrap or PrimeOne themes. Theme is the required css file to be imported, visit the Themes section for the complete list of available themes to choose from.
import 'primevue/resources/themes/aura-light-green/theme.css';
Unstyled Mode
Unstyled mode is disabled by default for all components. Using the PrimeVue plugin during installation, set unstyled
as true to enable it globally. Visit the Unstyled mode documentation for more information and examples.
import { createApp } from 'vue';
import PrimeVue from 'primevue/config';
const app = createApp(App);
app.use(PrimeVue, { unstyled: true });
Usage
Each component can be imported individually so that you only bundle what you use. Import path is available in the documentation of the corresponding component.
import Button from 'primevue/button';
const app = createApp(App);
app.component('Button', Button);
Prop Cases
Component prop names are described as camel case throughout the documentation however kebab-case is also fully supported. Events on the other hand should always be kebab-case.
<Dialog :showHeader="false"></Dialog>
<!-- can be written as -->
<Dialog :show-header="false"></Dialog>
Nuxt Integration
The nuxt-primevue package is the official module by PrimeTek.
# Using npm
npm install --save-dev nuxt-primevue
# Using yarn
yarn add --dev nuxt-primevue
# Using pnpm
pnpm add -D nuxt-primevue
The module is enabled by adding nuxt-primevue
to the modules option. Configuration values are defined with the primevue
property.
export default defineNuxtConfig({
modules: ['nuxt-primevue'],
primevue: {
}
});
Whether to install the PrimeVue plugin, defaults to true. Disable this option if you prefer to configure PrimeVue manually e.g. with a Nuxt plugin.
primevue: {
usePrimeVue: true;
}
The names of the components, directives and composables to import and register are provided using the include property. When the value is ignored or set using the * alias, all of the components, directives and composables are registered respectively.
primevue: {
components: {
include: ['Button', 'DataTable']
},
directives: {
include: ['Ripple', 'Tooltip']
},
composables: {
include: ['useStyle']
}
}
In styled mode, the theme can be defined at Nuxt configuration with the css property. Note that this only applies to styled mode, in unstyled mode a theme file is not required as styling is done externally.
export default defineNuxtConfig({
css: ['primevue/resources/themes/aura-dark-green/theme.css']
});
For detailed information
Example
We've created various samples for the popular options in the Vue ecosystem. Visit the primevue-examples repository for the samples.
Contributors