Skip to content

Instantly share code, notes, and snippets.

@coltborg
Created December 11, 2019 01:06
Show Gist options
  • Save coltborg/c5120d36f0002f86bc50ab9db60f97ac to your computer and use it in GitHub Desktop.
Save coltborg/c5120d36f0002f86bc50ab9db60f97ac to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Watch
<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