Unclear areas of computed caching #12856
Answered
by
skirtles-code
Nokic233
asked this question in
Help/Questions
-
case 1: <script setup>
import { reactive, computed } from 'vue'
const state = reactive({ count: 1 })
const double = computed(() => {
console.log('c');
return 2
})
console.log(double.value)
console.log(double.value)
// output:
// c
// 2
// 2
</script>
case 2: <script setup>
import { reactive, computed } from 'vue'
const state = reactive({ count: 1 })
const double = computed(() => {
console.log('c');
return 2
})
console.log(double.value)
state.count++ // add code
console.log(double.value)
// expect output
// c
// 2
// 2
// actual output
// c
// 2
// c
// 2
</script>
Why does changing a state variable that is not used in computing properties cause the cache of computing properties to become invalid? |
Beta Was this translation helpful? Give feedback.
Answered by
skirtles-code
Feb 11, 2025
Replies: 1 comment
-
I believe it's the bug described at #12337. It's a regression that occurred in 3.5.6 (it works as you're expecting in 3.5.5). It also only affects a |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Nokic233
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe it's the bug described at #12337. It's a regression that occurred in 3.5.6 (it works as you're expecting in 3.5.5). It also only affects a
computed
with no dependencies, which is rare in practice.