0

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.

1
  • what have tried so far, please share the code Commented Jul 16, 2021 at 18:29

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.