javascript / beginner
Snippet
Computed Properties for Logic
Computed properties are derived values that are automatically updated whenever their dependencies change. They are cached based on their reactive dependencies, making them efficient.
snippet.js
1
2
3
4
5
6
<script setup>import { ref, computed } from 'vue';const count = ref(5);const doubleCount = computed(() => count.value * 2);</script>
vue
Breakdown
1
computed(() => ...)
Creates a reactive reference that calculates its value based on other refs.
2
count.value * 2
The logic that defines the computed value, which re-runs if count changes.