Vue

vue/no-reactivity-loss

Never destructure or reassign a reactive() object; use toRefs, a ref, or change its properties.

umiarkowanastatycznefe-vue

Dlaczego

Reactivity is tracked through the proxy that reactive() returns. const { count } = state copies the current value into a plain variable that never updates, and state = reactive({...}) replaces the proxy the template and watchers still hold, so the screen keeps showing the old object.

Poprawka

Prefer ref() for state you replace as a whole (user.value = next). To pass parts of a reactive object around, use toRefs(state) or toRef(state, 'count'), or a getter (() => state.count). To update many fields, mutate in place: Object.assign(state, next). Props destructured in <script setup> stay reactive since Vue 3.5; wrap them in a getter when passing them to watch.

Przykłady

// bad
const state = reactive({ count: 0 })
const { count } = state
// good
const state = reactive({ count: 0 })
const { count } = toRefs(state)

Źródła

Fakty

Identyfikator
vue/no-reactivity-loss
Waga
umiarkowana
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
vue
Tylko w projektach z
vue nuxt
Uczy jej skill
fe-vue Vue components
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain vue/no-reactivity-loss