2021年3月18日星期四

How to trigger function when @keyup.delete input until it is empty? VueJS

In my DOM I have an input area, enter it with some text to insert a tag

<input @keyup.delete="inputBackspace()" @keyup.enter="insert_tag()">

and here is my methods

insert_tag() {    let value = this.tagInput    this.tags.push(value)    this.tagInput = ''  },  inputBackspace() {    if (this.tagInput === '') this.tags.splice(-1, 1)  }  

But the above method is not the result I want, it triggers splice function when the tag is instantly empty by entering backspace. I prefer to enter backspace to let the input value become empty first, after that enter backspace again to trigger the splice function.

https://stackoverflow.com/questions/66688223/how-to-trigger-function-when-keyup-delete-input-until-it-is-empty-vuejs March 18, 2021 at 05:28PM

没有评论:

发表评论