Last active
May 23, 2025 07:09
-
-
Save Kcko/c177f7c65ac8956866594f1a67985ed3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 Když neobalíš objekt do reactive(): | |
const filtersStorage = { | |
priceValue: computed({ | |
get: () => selectedFilters.value.priceValue, | |
set: v => selectedFilters.value.priceValue = +v | |
}) | |
} | |
// Pak filtersStorage.priceValue je přímo ComputedRef objekt. A ComputedRef se chová jako ref - musíš použít .value pro přístup k hodnotě: | |
// Bez reactive() wrapper | |
filtersStorage.priceValue.value // ✅ musíš použít .value | |
// 2 | |
// Když obalíš objekt do reactive(): | |
const filtersStorage = reactive({ | |
priceValue: computed(...) | |
}) | |
// S reactive() wrapper | |
filtersStorage.priceValue // ✅ .value se přidá automaticky | |
/* | |
Proč se to děje? | |
reactive() má speciální chování - automaticky unwrapuje refs na prvním levelu objektu | |
Tohle je záměrné chování pro lepší DX (developer experience) | |
Bez reactive() wrapper pracuješ přímo s ComputedRef objektem | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment