How to add a button in VueJS?
January 12, 2023Hi Friends đź‘‹,
Welcome To SortoutCode! ❤️
Today, I am going to show you How do you add a button in VueJS?
Table of Content
- Setup the Vue (Optional)
- Create FirstComponent.vue and import it into App.js
- Add button
This article will guide you to how do I add a button in vueJS.
Setup the Vue (Optional)
First, we have to install the Vue project, I had installed the vueJS in my system. If you haven’t installed or have any problem with installation you can follow this article, it will show you step by step process of installation.
How to Install the VueJS project?
Create FirstComponent.vue and import it into App.js
Create the new component in the src/components/
components folder. the component name is FirstComponent.vue
and imported into the App.js
file:
App.js
<template>
<div id="app">
<FirstComponent />
</div>
</template>
<script>
import FirstComponent from "./components/FirstComponent.vue";
export default {
name: "App",
components: {
FirstComponent,
},
};
</script>
Add button
To add a button we are going to add the button
tag. Let’s see the code example:
FirstComponent.js
<template>
<div id="app">
<button>Sortoutcode</button>
</div>
</template>
<script>
export default {
name:'FirstComponent'
}
</script>
For now, let’s check the output.
All the best 👍.