[Vuejs]-Vue/Javascript – Unable to clear input after paste event

3πŸ‘

βœ…

You can use the prevent modifier on paste to prevent the native event and you don’t need to use the $ref in this case.

Check @paste.prevent:

new Vue({
  el: "#app",
  data: {
    todo: ''
  },
  methods: {
    onPaste: function(event) {
      let clipped = event.clipboardData.getData('text');
      console.log(clipped)
      this.todo = '';
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <input type="text" v-model="todo" @keyup.enter="addTodo" @paste.prevent="onPaste">
</div>

Leave a comment