Skip to content

Instantly share code, notes, and snippets.

@yann-yinn
Created January 5, 2022 08:47
Show Gist options
  • Save yann-yinn/114db71e1afa1544a2c1d009467dc245 to your computer and use it in GitHub Desktop.
Save yann-yinn/114db71e1afa1544a2c1d009467dc245 to your computer and use it in GitHub Desktop.
watch Versus watchEffect
<script setup lang="ts">
import { ref, watch, watchEffect } from "vue";
const price = ref(10);
const quantity = ref(1);
watchEffect(() => {
console.log("watchEffect()", price.value, quantity.value);
});
watch(price, () => {
console.log("watch()", price.value, quantity.value);
});
</script>
<template>
<main>
<div>Prix: <input v-model="price" type="number" /></div>
<div>Quantité: <input v-model="quantity" type="number" /></div>
</main>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment