Skip to content

Commit 20c402c

Browse files
committed
Replace @input with v-model
1 parent e39df7c commit 20c402c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/components/InputSearch.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="row input-search">
33
<div class="input-field col s12">
44
<i class="material-icons prefix">search</i>
5-
<input id="search" type="search" @input="onChange" autocomplete="off" />
5+
<input id="search" type="search" v-model="searchTerm" autocomplete="off" />
66
<label for="search">{{ label }}</label>
77
</div>
88
</div>
@@ -17,9 +17,22 @@ export default {
1717
required: true
1818
}
1919
},
20-
methods: {
21-
onChange({ target: { value } }) {
22-
this.$emit("input", value.trim());
20+
data() {
21+
return {
22+
searchTerm: ""
23+
};
24+
},
25+
activated() {
26+
this.searchTerm = "";
27+
// We are using keep-alive, and when we leave the screen while the input is focused all
28+
// the states are preserved, so we need to restore the input to its initial state.
29+
this.$nextTick(() => {
30+
M.updateTextFields();
31+
});
32+
},
33+
watch: {
34+
searchTerm(newVal) {
35+
this.$emit("input", newVal.trim());
2336
}
2437
}
2538
};

0 commit comments

Comments
 (0)