Here is a textarea where I want to enter multiple line input Textarea input field in Vue js with multiple lines input
And I wanted to convert the input data into an array format data like ['Value 1','Value 2', ...] in Vue.js. Thank you.
Here is a textarea where I want to enter multiple line input Textarea input field in Vue js with multiple lines input
And I wanted to convert the input data into an array format data like ['Value 1','Value 2', ...] in Vue.js. Thank you.
You could create a computed property that returns the textarea content splitted by \n which represents the new line character:
// ignore the following two lines, they just disable warnings in "Run code snippet"
Vue.config.devtools = false;
Vue.config.productionTip = false;
new Vue({
el: '#app',
data() {
return {
content:''
}
},
computed:{
contentArr(){
return this.content.split('\n')
}
}
})
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app" class="container">
<textarea v-model="content">
</textarea>
<ul>
<li v-for="item in contentArr">{{item}}</li>
</ul>
</div>