Installation
Setting up Preline UI in a Vue.js project using Tailwind CSS.
Please note that the plugin has been tested with the latest version of the framework (v3.3.4). The framework was installed using the standard npm create vue@latest
command.
If you are using your own project structure, be mindful of file paths!
The Progressive JavaScript Framework. If you haven't set up Tailwind CSS yet, check out Vue Tailwind CSS installation guides.
Install preline
via npm or yarn.
// Terminal or Shellnpm install preline // or yarn add preline
Add the path to Preline UI JavaScript files in your tailwind.config.js
file.
// tailwind.config.jsmodule.exports = { content: [ './node_modules/preline/preline.js', ], plugins: [ require('preline/plugin'), ],}
Add the Preline UI JavaScript in your app entry point projects_root_directory/src/main.ts|js
import "preline/preline";
Add code that reinitializes the components every time the page is refreshed to your "route" projects_root_directory/src/router/index.ts|js
import { createRouter, createWebHistory } from 'vue-router'
import { type IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
...
const router = createRouter({
...
});
router.afterEach((to, from, failure) => {
if (!failure) {
setTimeout(() => {
window.HSStaticMethods.autoInit();
}, 100)
}
});
export default router;
Add code that reinitializes the components every time when app is mounted projects_root_directory/src/App.vue
<script setup>
import { onMounted } from 'vue';
import { type IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
onMounted(() => {
setTimeout(() => {
window.HSStaticMethods.autoInit();
}, 100)
});
</script>
...
Check out this section for community-shared tips and tricks. It's a spot for finding those handy hacks and solutions that enhance your experience with Preline UI.