|
1 | 1 | <script setup lang="ts"> |
2 | | -import { shallowRef } from 'vue' |
3 | | -import Foo from '../src/Foo.vue' |
4 | | -import Primitive from './primitive/Primitive.vue' |
| 2 | +import { computed, shallowRef, watchEffect } from 'vue' |
| 3 | +// import Foo from '../src/Foo.vue' |
| 4 | +// import Primitive from './primitive/Primitive.vue' |
| 5 | +import Toggle from './toggle/Toggle.vue' |
5 | 6 |
|
6 | | -const a1 = shallowRef() |
7 | | -const a2 = shallowRef() |
8 | | -const a3 = shallowRef() |
9 | | -const a4 = shallowRef() |
| 7 | +const open = shallowRef(true) |
| 8 | +const dis = shallowRef(true) |
| 9 | +function toggle() { |
| 10 | + open.value = !open.value |
| 11 | +} |
| 12 | +function toggleDis() { |
| 13 | + dis.value = !dis.value |
| 14 | +} |
| 15 | +
|
| 16 | +const on = computed(() => { |
| 17 | + if (!open.value) { |
| 18 | + return {} |
| 19 | + } |
| 20 | +
|
| 21 | + return { |
| 22 | + click: log, |
| 23 | + } |
| 24 | +}) |
| 25 | +
|
| 26 | +// watchEffect(() => { |
| 27 | +// console.log('open', on.value) |
| 28 | +// }) |
10 | 29 |
|
11 | | -function log() { |
| 30 | +// const a1 = shallowRef() |
| 31 | +// const a2 = shallowRef() |
| 32 | +// const a3 = shallowRef() |
| 33 | +// const a4 = shallowRef() |
| 34 | +
|
| 35 | +function log(event: Event) { |
| 36 | + if (dis.value) { |
| 37 | + event.preventDefault() |
| 38 | + } |
12 | 39 | console.error('click') |
13 | 40 | } |
14 | 41 | </script> |
15 | 42 |
|
16 | 43 | <template> |
17 | 44 | <div> |
| 45 | + <button @click="toggle"> |
| 46 | + ON {{ open }} |
| 47 | + </button> |
| 48 | + <button @click="toggleDis"> |
| 49 | + Dis {{ dis }} |
| 50 | + </button> |
18 | 51 | <div> |
19 | | - <Primitive ref="a1" class="baz" @click="log"> |
| 52 | + <!-- <Primitive ref="a1" class="baz" @click="log"> |
20 | 53 | content |
21 | | - </Primitive> |
| 54 | + </Primitive> --> |
22 | 55 | </div> |
23 | 56 | <div> |
24 | | - <Primitive ref="a2" as="button" type="button" class="baz" @click="log"> |
| 57 | + <!-- <Primitive ref="a2" as="button" type="button" class="baz" @click="log"> |
25 | 58 | content |
26 | | - </Primitive> |
| 59 | + </Primitive> --> |
27 | 60 | </div> |
28 | 61 | <div> |
29 | | - <Primitive ref="a3" as-child class="baz" @click="log"> |
| 62 | + <!-- <Primitive ref="a3" as-child class="baz" @click="log"> |
30 | 63 | <button type="button"> |
31 | 64 | content |
32 | 65 | </button> |
33 | | - </Primitive> |
| 66 | + </Primitive> --> |
34 | 67 | </div> |
35 | 68 | <div> |
36 | | - <Primitive ref="a4" :as="Foo" class="baz" @click="log"> |
| 69 | + <!-- <Primitive ref="a4" :as="Foo" class="baz" @click="log"> |
37 | 70 | content |
38 | | - </Primitive> |
| 71 | + </Primitive> --> |
| 72 | + </div> |
| 73 | + <div> |
| 74 | + <Toggle v-on="on"> |
| 75 | + Toggle |
| 76 | + </Toggle> |
| 77 | + <!-- <button @click="log"> |
| 78 | + Toggle |
| 79 | + </button> --> |
| 80 | + </div> |
| 81 | + <div> |
| 82 | + <pre>{{ on }}</pre> |
39 | 83 | </div> |
40 | 84 | </div> |
41 | 85 | </template> |
|
0 commit comments