Vue Accordion Component
A simple and lightweight Vue 3 accordion component plugin. Supports both global plugin registration and local component usage. Written in TypeScript. The accordion component contains a minimum of CSS styles, which makes it easy to integrate into any of your designs. You can install the component using the NPM or Yarn package managers. The component allows you to configure the ability to have one or several elements of the accordion active at the same time. The CSS class “active” is added to the open accordion element.
Demo: https://vue.webstep.top/ws-acc
Installation
# via npm npm install vue-ws-acc # or via yarn yarn add vue-ws-acc
Usage
1. Global registration (as a plugin)
import { createApp } from 'vue';
import App from './App.vue';
import VueWsAcc from 'vue-ws-acc';
import 'vue-ws-acc/dist/vue-ws-acc.css';
const app = createApp(App);
app.use(VueWsAcc);
app.mount('#app');
Now the component <VueWsAcc /> is available globally.
2. Local registration (per component)
<template>
<VueWsAcc :items="accordionItems" />
</template>
<script lang="ts" setup>
import VueWsAcc from 'vue-ws-acc';
import 'vue-ws-acc/dist/vue-ws-acc.css';
const accordionItems = [
{ title: 'Section 1', content: 'Content for section 1' },
{ title: 'Section 2', content: 'Content for <strong>section</strong> 2' }
];
</script>
The “content” value may contain HTML tags.
Multiple
By default, only one accordion element can be active at a time. However, this behavior can be changed using the “multi” attribute, allowing multiple elements to be active at once.
<VueWsAcc :items="accordionItems" multi />
Styles
The component uses a minimum of CSS styles. These styles are easy to override. However, if you need to disable optional component styles, you can do so using the “simple” attribute.
<VueWsAcc :items="accordionItems" simple />
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items |
Array | [] |
Array of accordion items |
simple |
Boolean | false |
Disable optional styles |
multi |
Boolean | false |
Allow multiple sections open |
Example item: { title: string, content: string }
NPM: https://www.npmjs.com/package/vue-ws-acc
GitHub: https://github.com/igorrybalko/vue-ws-acc
Similar posts:
-
How to Detect Scroll Direction on a Page Using JavaScript
Sometimes it is necessary to detect the direction of vertical scrolling on a website in order to dynamically change the behavior of interface elements. For example, this ...
-
How to Get Max Value in JavaScript Array
A short note about finding the maximum value in a JavaScript array with numeric values. The Array object in JS does not have its own max method. To find the maximum va...
-
jQuery Accordion Plugin
An accordion is often used on websites. This element is popular and convenient at the same time. An accordion helps to structure content and save space. In my work, I oft...
Hi my friend! I wish to say that this post is amazing, nice written and include almost all vital infos. I would like to see extra posts like this .
Hello there! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche. Your blog provided us valuable information to work on. You have done a wonderful job!
I have been exploring for a little for any high-quality articles or weblog posts in this sort of space . Exploring in Yahoo I eventually stumbled upon this web site. Reading this info So i’m glad to express that I have an incredibly just right uncanny feeling I found out exactly what I needed. I such a lot unquestionably will make sure to do not overlook this web site and provides it a look on a continuing basis.