Created
December 11, 2019 01:06
-
-
Save coltborg/c5120d36f0002f86bc50ab9db60f97ac to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Watch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
Search for <input v-model="searchInput" /> | |
<div> | |
<p>Number of events: {{ results }}</p> | |
</div> | |
</div> | |
</template> | |
<script> | |
import { ref, watch } from "@vue/composition-api"; | |
import eventApi from "@/api/event.js"; | |
export default { | |
setup() { | |
const searchInput = ref(""); | |
const results = ref(0); | |
// This only runs once! | |
// So move it into watch 👇 | |
// results.value = eventApi.getEventCount(searchInput.value); | |
watch(() => { | |
results.value = eventApi.getEventCount(searchInput.value); | |
}); | |
return { searchInput, results }; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment