new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vue · Tutorial · all subjects

tutorial/watchers

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

watch() function for Composition API

In the Composition API, the watch() function accepts a ref as the first argument and a callback function as the second argument. The callback receives the new value as its parameter and fires whenever the watched ref's value changes. Example: watch(count, (newCount) => { console.log(`new count is: ${newCount}`) })

watch option in Options API

In the Options API, the watch option is an object on the component where each property name matches a data property to watch. The property value is a callback function that receives the new value as its argument. The callback fires when the watched property changes. Example: watch: { count(newCount) { console.log(`new count is: ${newCount}`) } }

Side effects and watchers

Watchers enable performing side effects reactively. A side effect is an operation like logging to the console or fetching data that happens in response to a data change. This is distinct from computed properties and rendering.

watch() can watch multiple data source types

The watch() function in the Composition API can directly watch a ref, and can also watch other types of data sources. Details on all supported data sources are covered in the Guide - Watchers section of the documentation.

Practical use case: fetching data on ID change

A practical use of watchers is fetching new data when an ID changes. When a user clicks a button to change a todo ID, a watcher can be set up to automatically fetch the corresponding todo data from an API.

Give your agent this brain