How to get data from textarea in VueJS?
April 11, 2023Hi Friends đź‘‹,
Welcome To SortoutCode! ❤️
To get the content from textarea in VueJS. We are going to use the v-model
component of VueJS. Using the component v-model
we can implement the two-way binding.
Short solution
parentComp.vue
<textarea v-modal="title"></textarea>
Today, I am going to show you How you get data from textarea in VueJS?
Table of Content
- Setup the Vue (Optional)
- Create FirstComponent.vue and import it into App.js
- How to get data from textarea?
This article will guide you to How do I get data from textarea in vueJS
Setup the Vue.js
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>
<FirstComp />
</template>
<script>
import FirstComp from "./components/FirstComp.vue";
export default {
name: "App",
components: {
FirstComp: FirstComp,
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
How to get data from textarea?
To access the data from textarea in vuejs. We are going to use the v-model
component which is provided by the vuejs. Component v-model
is used as two-way data binding.
Let’s take a short example to better understand.
FirstComp.vue
<template>
<div class="app-data">
<h1>Welcome to sortoutcode.com</h1>
<textarea v-model="description" cols="30" rows="10"></textarea>
<p v-if="getdescription">{{ getdescription }}</p>
<button @click="getData">Get Data</button>
</div>
</template>
<script>
export default {
name: "FirstComp",
data() {
return {
description: "",
getdescription: "",
};
},
methods: {
getData() {
this.getdescription = this.description;
},
},
};
</script>
<style scoped>
.app-data {
display: flex;
flex-direction: column;
align-items: center;
}
button {
margin-top: 15px;
}
</style>
For now, let’s check the output.
Output
Links
Here, is the above program code sandbox link of how to get data from textarea in vue js. Then you can use it whenever you went and do the changes as per your requirements.
All the best 👍.