Getting Started with the Vue Accordion Component in Vue 2
30 Jul 20264 minutes to read
This article provides a step-by-step guide for setting up a Vue 2 project using Vue-CLI and integrating the Syncfusion® Vue Accordion component.
To get start quickly with Vue Accordion, you can check on this video:
Prerequisites
System requirements for Syncfusion® Vue UI components
Setup the Vue 2 project
Easily set up a Vue 2 application using Vue CLI, which provides a reliable development environment, a streamlined project structure, and optimized builds compared to older setup tools. For detailed steps, refer to the Vue CLI installation instructions.
Note: To create a Vue 2 application using Vue CLI, refer to this documentation for more details.
To create a new Vue 2 application, run the following commands based on your preferred package manager:
npm install -g @vue/cli
vue create quickstartor
yarn global add @vue/cli
vue create quickstartDuring the setup process, the CLI will prompt you for a few configuration options. Select the following:
- Which linter to use? → Default ([Vue 2] babel, eslint)
- Install with npm and start now? → Yes
Selecting Yes automatically installs the project dependencies and starts the development server.
After verifying that the application starts successfully, terminate the development server in the terminal and proceed to the next step.
Navigate to the project directory:
cd quickstartAdding Vue Accordion packages
To install the Accordion package, use the following command:
npm install @syncfusion/ej2-vue-navigations --saveor
yarn add @syncfusion/ej2-vue-navigationsAdding CSS reference
Themes for Syncfusion® components can be applied using CSS files provided through npm theme packages. For available themes, refer to the Themes documentation.
Install the Material 3 theme package using the following command:
npm install @syncfusion/ej2-material3-theme --saveThen add the following CSS reference to the src/App.vue file:
<style>
@import "../node_modules/@syncfusion/ej2-material3-theme/styles/accordion/index.css";
</style>Adding Accordion component
The Accordion code should be added in the src/App.vue file.
<template>
<div>
<ejs-accordion>
<e-accordionitems>
<e-accordionitem expanded='true' header='ASP.NET' content='Microsoft ASP.NET is a set of technologies in the Microsoft .NET Framework for building Web applications and XML Web services.'></e-accordionitem>
<e-accordionitem header='ASP.NET MVC' content='The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller.'></e-accordionitem>
<e-accordionitem header='JavaScript' content='JavaScript (JS) is an interpreted computer programming language.It was originally implemented as part of web browsers so that client-side scripts could interact with the user, control the browser, communicate asynchronously, and alter the document content that was displayed.'></e-accordionitem>
</e-accordionitems>
</ejs-accordion>
</div>
</template>
<script>
import { AccordionComponent, AccordionItemDirective, AccordionItemsDirective } from '@syncfusion/ej2-vue-navigations';
export default {
name: 'app',
components: {
'ejs-accordion': AccordionComponent,
'e-accordionitems': AccordionItemsDirective,
'e-accordionitem': AccordionItemDirective
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-material3-theme/styles/accordion/index.css";
</style>Run the Application
npm run serveor
yarn run serve