While working on a Vue app, I implemented a paste listener
for a textarea
to trigger validation code whenever a user pastes data into the field. However, despite being able to see the pasted data in the console under event -> target -> value
, I am unable to access it using event.target.value
. What could be the issue here?
Here's a minimal example:
<div id="app">
<textarea name="myField" @paste="onPaste"></textarea>
<p>Field name: {{ fieldName }}</p>
<p>Pasted data: {{ pasted }}</p>
</div>
var app = new Vue({
el: '#app',
data: {
fieldName: '',
pasted: ''
},
methods: {
onPaste(event){
console.log(event)
this.message = event.target.name
this.paste = event.target.value
}
}
})