Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Watching Data with watch | Section
Vue.js Fundamentals and App Development

bookWatching Data with watch

Свайпніть щоб показати меню

Vue allows you to run code in response to changes in reactive data using the watch() function.

A watcher observes a value and executes a function when that value changes.

<script setup>
import { ref, watch } from "vue";

const count = ref(0);

watch(count, (newValue, oldValue) => {
  console.log("Count changed from", oldValue, "to", newValue);
});
</script>

<template>
  <button @click="count++">Increase</button>
</template>

Each time the value changes, the watcher runs and receives the new and previous values.

Watchers are useful when you need to perform side effects, such as logging, API calls, or reacting to changes outside the template.

question mark

What is the main use case for the watch function in Vue?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 15

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 15
some-alt