[Vuejs]-Vue JS: Reset/Clear value from input

3πŸ‘

βœ…

Found an answer:

Adding a v-model to it and then setting that have a empty string seems to do the trick.

<input type="text" placeholder="Search for tags..." v-on:keyup.enter="searchTag" v-model="searchText">


export default {
    data() {
        return {
            tags: [
            ],
            searchText: ""
        }
    },
    methods: {
        searchTag: function(event) {
            var newtag = event.target.value;
            this.tags.push({name: newtag});
            this.searchText = "";
        }
    }
}

Note that the searchText is set to β€œβ€ at the end of the search function.

πŸ‘€user3479267

2πŸ‘

Just bind the input value to a variable and then clear it on the event like this :

data{
  input : ''
},
methods: {
   searchTag: function() {
       this.input = '';
   }
}
<input type="text" placeholder="Search for tags..."  v-on:keyup.enter="searchTag" v-model="input">

0πŸ‘

Vue is plain js. Of course you can use it.

πŸ‘€Yesthe Cia

Leave a comment