Vue

vue/ref-value-in-script

In script code, read and compare a ref or computed through .value; the ref object itself is always truthy.

umiarkowanastatycznefe-vue

Dlaczego

Templates unwrap refs, script code does not. if (isOpen) tests the ref object, which is always truthy, so the branch always runs; count + 1 gives "[object Object]1", and items === null is never true. The code type-checks loosely in JavaScript and fails only at run time.

Poprawka

Use .value in script: if (isOpen.value), count.value + 1. In the template keep the plain name. If a value never needs to be reactive on its own, group it in an object returned from a composable rather than mixing refs and plain values.

Przykłady

// bad
const isOpen = ref(false)
function toggle() { if (isOpen) close() }
// good
const isOpen = ref(false)
function toggle() { if (isOpen.value) close() }

Źródła

Fakty

Identyfikator
vue/ref-value-in-script
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/ref-value-in-script