The next element we are adding is <textarea> for multi-line text, which works the same way as <input>:
// src/components/basic.vue
<label for="message">Message</label>
<textarea v-model="form.message"></textarea>
export default {
data () {
return {
form: { message: null }
}
},
methods:{
checkForm (e) {
this.errors = []
if (!this.form.message) {
this.errors.push('Message required')
}
}
}
}
In the <script> block, we define a message property in the data function that holds the initial null value and will be updated on the input event from the <textarea> element. We validate the message data in the if condition block when you hit the submit button; if it has no data provided, then we push the error message to errors.