Skip to content

Commit 2e0d910

Browse files
committed
SearchFieldコンポーネントのinputをenterキーの時だけ機能するようにする
1 parent 9119b5a commit 2e0d910

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/SearchField.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
type="search"
55
placeholder="検索"
66
:value="value"
7-
@input="$emit('input', $event.target.value)"
7+
@keydown.enter="search"
88
/>
99
</template>
1010

@@ -18,6 +18,12 @@ export default Vue.extend({
1818
default: '',
1919
},
2020
},
21+
methods: {
22+
search($event: { keyCode: number; target: { value: string } }): void {
23+
if ($event.keyCode !== 13) return
24+
this.$emit('input', $event.target.value)
25+
},
26+
},
2127
})
2228
</script>
2329

0 commit comments

Comments
 (0)