How can I help you?
Getting Started with the Vue Barcode Component in Vue 2
10 Feb 202617 minutes to read
This guide walks you through creating a Vue 2 application using Vue-CLI and integrating the Syncfusion® Vue Barcode component
Ready to streamline your Syncfusion® Vue development? Discover the full potential of Syncfusion® Vue components with Syncfusion® AI Coding Assistant. Effortlessly integrate, configure, and enhance your projects with intelligent, context-aware code suggestions, streamlined setups, and real-time insights—all seamlessly integrated into your preferred AI-powered IDEs like VS Code, Cursor, Syncfusion® CodeStudio and more. Explore Syncfusion® AI Coding Assistant
Prerequisites
System requirements for Syncfusion® Vue UI components
Dependencies
The following list of dependencies are required to use the Barcode Generator component in your application.
|-- @syncfusion/ej2-vue-barcode-generator
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-data
|-- @syncfusion/ej2-navigations
|-- @syncfusion/ej2-inputs
|-- @syncfusion/ej2-popups
|-- @syncfusion/ej2-buttons
|-- @syncfusion/ej2-lists
|-- @syncfusion/ej2-splitbuttons
|-- @syncfusion/ej2-barcode-generator
|-- @syncfusion/ej2-vue-baseSetup Vue Environment
Use Vue CLI to set up your Vue project. Install Vue CLI globally with the following command:
npm install -g @vue/clior
yarn global add @vue/cliCreate a Vue 2 Application
Create a new project using the vue create command.
vue create my-barcode-appWhen creating a new project, choose the option Default ([Vue 2] babel, eslint) from the menu.
once the my-barcode-app project is created, navigate to the project folder:
cd my-barcode-appAdd Syncfusion® Vue Barcode packages
All Syncfusion® packages are published to the npmjs.com registry.
Install the @syncfusion/ej2-vue-barcode-generator package by running the following command:
npm install @syncfusion/ej2-vue-barcode-generator --saveor
yarn add @syncfusion/ej2-vue-barcode-generatorAdd Syncfusion® Vue component
Follow the below steps to add the Vue Barcode component using Composition API or Options API:
1. First, import and register the Barcode component in the script section of the src/App.vue file. If you are using the Composition API, you should add the setup attribute to the script tag to indicate that Vue will be using the Composition API.
<script setup>
import { QRCodeGeneratorComponent as EjsQrcodegenerator } from '@syncfusion/ej2-vue-barcode-generator';
</script><script>
import { QRCodeGeneratorComponent } from '@syncfusion/ej2-vue-barcode-generator';
export default {
components: {
'ejs-qrcodegenerator': QRCodeGeneratorComponent
}
}
</script>2. In the template section, define the Barcode component with width, height, value, mode property.
<template>
<div id="app" class="barcodeStyle">
<ejs-qrcodegenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:value="value"
:mode="mode"
></ejs-qrcodegenerator>
</div>
</template>3. Declare the value for width, height, value, mode property in the script section
<script setup>
const width = "200px";
const height = "150px";
const type = "Codabar";
const value = "123456789";
const mode = "SVG";
</script><script>
import { QRCodeGeneratorComponent } from '@syncfusion/ej2-vue-barcode-generator';
export default {
name: "App",
components: {
"ejs-qrcodegenerator": QRCodeGeneratorComponent
},
data() {
return {
width: "200px",
height: "150px",
type: "Codabar",
value: "123456789",
mode: "SVG",
}
}
}
</script>4. Run the project
Use either npm or yarn:
npm run serveor
yarn run serveNOTE
Vue CLI projects automatically rebuild when you save changes—no need to rerun the command each time.
Here is the summarized code for the above steps in the src/App.vue file:
<template>
<div id="app" class="barcodeStyle">
<ejs-barcodegenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:type="type"
:value="value"
:mode="mode"
></ejs-barcodegenerator>
</div>
</template>
<style>
.barcodeStyle {
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<script setup>
import { BarcodeGeneratorComponent as EjsBarcodegenerator} from '@syncfusion/ej2-vue-barcode-generator';
const width = "200px";
const height = "150px";
const mode = "SVG";
const type = "Codabar";
const value = "123456789";
</script><template>
<div id="app" class="barcodeStyle">
<ejs-barcodegenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:type="type"
:value="value"
:mode="mode"
></ejs-barcodegenerator>
</div>
</template>
<style>
.barcodeStyle {
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<script>
import { BarcodeGeneratorComponent } from '@syncfusion/ej2-vue-barcode-generator';
export default {
name: "App",
components: {
"ejs-barcodegenerator":BarcodeGeneratorComponent
},
data () {
return {
width: "200px",
height: "150px",
type: "Codabar",
value: "123456789",
mode: "SVG",
}
}
}
</script>Adding QR Generator control
You can add QR codes using the barcode generator component.
<template>
<div id="app" class="barcodeStyle">
<ejs-qrcodegenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:value="value"
:mode="mode"
></ejs-qrcodegenerator>
</div>
</template>
<style>
.barcodeStyle {
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<script setup>
import { QRCodeGeneratorComponent as EjsQrcodegenerator } from '@syncfusion/ej2-vue-barcode-generator';
const width = "200px";
const height = "150px";
const mode = "SVG";
const value = "Syncfusion";
</script><template>
<div id="app" class="barcodeStyle">
<ejs-qrcodegenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:value="value"
:mode="mode"
></ejs-qrcodegenerator>
</div>
</template>
<style>
.barcodeStyle {
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<script>
import { QRCodeGeneratorComponent } from '@syncfusion/ej2-vue-barcode-generator';
export default {
name: "App",
components: {
"ejs-qrcodegenerator":QRCodeGeneratorComponent
},
data () {
return {
width: "200px",
height: "150px",
mode: "SVG",
value: "Syncfusion",
}
}
}
</script>Adding Data Matrix Generator control
You can add Data Matrix codes using the barcode generator component.
<template>
<div id="app" class="barcodeStyle">
<ejs-datamatrixgenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:value="value"
:mode="mode"
></ejs-datamatrixgenerator>
</div>
</template>
<style>
.barcodeStyle {
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<script setup>
import { DataMatrixGeneratorComponent as EjsDatamatrixgenerator } from '@syncfusion/ej2-vue-barcode-generator';
const width = "200px";
const height = "150px";
const mode = "SVG";
const value = "Syncfusion";
</script><template>
<div id="app" class="barcodeStyle">
<ejs-datamatrixgenerator
id="barcode"
ref="barcodeControl"
:width="width"
:height="height"
:value="value"
:mode="mode"
></ejs-datamatrixgenerator>
</div>
</template>
<style>
.barcodeStyle {
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<script>
import { DataMatrixGeneratorComponent } from '@syncfusion/ej2-vue-barcode-generator';
export default {
name: "App",
components: {
"ejs-datamatrixgenerator":DataMatrixGeneratorComponent
},
data () {
return {
width: "200px",
height: "150px",
mode: "SVG",
value: "Syncfusion",
}
}
}
</script>