From harness-claude
React to reactive data changes in Vue using watch and watchEffect for side effects like API calls, localStorage writes, debounced search, auto-save, and data sync.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> React to data changes with watch and watchEffect for side effects and async operations
Explains Vue 3 Proxy-based reactivity with refs, reactive, shallowRef, customRef, computed, and watchers for managing complex state in applications.
Guides selection and implementation of VueUse composables for state management, reactivity, and utilities in Vue.js and Nuxt projects.
Guides selection and implementation of VueUse composables like useAsyncState, createGlobalState for concise Vue.js and Nuxt features.
Share bugs, ideas, or general feedback.
React to data changes with watch and watchEffect for side effects and async operations
watch(source, callback) when you need the old and new values.watchEffect(callback) when you want automatic dependency tracking.{ deep: true } to watch nested object mutations.onCleanup callback to prevent leaks.import { ref, watch, watchEffect } from 'vue';
const query = ref('');
// Explicit source — gives old and new
watch(query, (newVal, oldVal) => {
console.log(`Query changed: ${oldVal} → ${newVal}`);
});
// Auto-tracked dependencies
watchEffect((onCleanup) => {
const controller = new AbortController();
fetch(`/api/search?q=${query.value}`, { signal: controller.signal });
onCleanup(() => controller.abort());
});
{ immediate: true } with watch to run the callback immediately on setup.watch([ref1, ref2], ([new1, new2], [old1, old2]) => { ... }).Vue provides two watcher APIs. watch() is explicit — you declare what to watch and get old/new values. watchEffect() is implicit — it automatically tracks any reactive dependency accessed during execution. Both return a stop function to cancel the watcher.
Trade-offs:
watchEffect can trigger unexpectedly if it accesses reactive data you did not intend to track{ flush: 'sync' } if you need synchronous execution (rare)When NOT to use:
computed() instead, which caches the resultref/reactive directly; Vue re-renders automaticallyhttps://patterns.dev/vue/watchers-pattern