-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathScriptSetup_Expose.vue
73 lines (56 loc) · 1.32 KB
/
ScriptSetup_Expose.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script setup lang="ts">
// imported components are also directly usable in template
import { ref } from 'vue'
import Hello from './Hello.vue'
/* ------ Common Test Case ------ */
const exposedState1 = 'exposedState1'
const exposedState2 = 'exposedState2'
const exposedState2Getter = () => {
return exposedState2;
}
const exposedRef = ref('exposedRef')
const exposedRefGetter = () => {
return exposedRef.value;
}
const exposedMethod1 = () => {
return 'result of exposedMethod1';
}
const exposedMethod2 = () => {
return 'result of exposedMethod2';
}
/* ------ Common Test Case End ------ */
const refNonExposed = ref('refNonExposed')
const refNonExposedGetter = () => {
return refNonExposed.value;
}
const count = ref(0)
const inc = () => {
count.value++
}
const resetCount = () => {
count.value = 0
}
defineExpose({
/* ------ Common Test Case ------ */
exposeObjectLiteral: 'exposeObjectLiteral',
exposedState1,
exposedState2Alias: exposedState2,
exposedState2Getter,
exposedRef,
exposedRefGetter,
exposedMethod1,
exposedMethod2Alias: exposedMethod2,
/* ------ Common Test Case End ------ */
count,
resetCount,
refNonExposedGetter,
})
defineOptions({
name: 'Hello',
})
</script>
<template>
<button @click="inc">{{ count }}</button>
<div>{{ refNonExposed }}</div>
<Hello />
</template>