I am attempting to convert some data to lowercase (always lowercase)
I am creating a search input like :
<template id="search">
<div>
<input type="text" v-model="search">
<li v-show="'hello'.includes(search) && search !== ''">Hello</li>
</div>
</template>
Vuejs : (component)
Vue.component('search', {
template : '#search',
data: function(){return{
search : '',
}}
});
I have attempted using the watch
method, but I do not want the input showing in lowercase while typing
watch: {
'search' : function(v) {
this.search = v.toLowerCase().trim();
}
}
Demo : https://jsfiddle.net/rgr2vnjp/
Furthermore, I prefer not to add .toLowerCase()
on the search list v-show
like :
<li v-show="'hello'.includes(search.toLowerCase()) && search !== ''">Hello</li>
Any suggestions? I have researched and found many suggesting to use filter
, but it is not available in Vuejs 2
Playground : https://jsfiddle.net/zufo5mhq/ (Try typing H)
PS: Any tips for good / better code would also be appreciated. Thank you