1// directly watching a ref
2
3const selected = ref(props.selected)
4
5watch(selected, (selection, prevSelection) => {
6 /* ... */
7})
8
1<template>
2 <button @click="increment">
3 Count is: {{ state.count }}, double is: {{ state.double }}
4 </button>
5</template>
6
7<script>
8import { reactive, computed } from 'vue'
9
10export default {
11 setup() {
12 const state = reactive({
13 count: 0,
14 double: computed(() => state.count * 2)
15 })
16
17 function increment() {
18 state.count++
19 }
20
21 return {
22 state,
23 increment
24 }
25 }
26}
27</script>
28