@@ -31,7 +31,6 @@ Anthony Fu
31
31
</div >
32
32
</div >
33
33
34
-
35
34
---
36
35
layout: 'intro'
37
36
---
@@ -55,7 +54,6 @@ A fanatical full-time open sourceror.<br>
55
54
56
55
<img src =" https://antfu.me/avatar.png " class =" rounded-full w-40 abs-tr mt-16 mr-12 " alt =" A comic art image of Anthony Fu " />
57
56
58
-
59
57
---
60
58
name: Sponsors
61
59
layout: center
@@ -74,7 +72,6 @@ layout: center
74
72
75
73
# Composable Vue
76
74
77
-
78
75
---
79
76
name: VueUse
80
77
layout: center
@@ -106,7 +103,6 @@ layout: center
106
103
</div >
107
104
</div >
108
105
109
-
110
106
---
111
107
layout: center
112
108
class: text-center
@@ -116,7 +112,6 @@ class: text-center
116
112
117
113
a brief go-through
118
114
119
-
120
115
---
121
116
122
117
<div class =" grid grid-cols-2 gap-x-4 " ><div >
@@ -175,7 +170,6 @@ bar.prop = 1
175
170
</div >
176
171
</div ></div >
177
172
178
-
179
173
---
180
174
181
175
# Ref Auto Unwrapping <MarkerCore />
@@ -224,7 +218,6 @@ data.foo // 'bar'
224
218
225
219
</div >
226
220
227
-
228
221
---
229
222
230
223
# ` unref ` - Opposite of Ref <MarkerCore />
@@ -260,7 +253,6 @@ unref(bar) // 'bar'
260
253
261
254
</div ></div >
262
255
263
-
264
256
---
265
257
layout: center
266
258
class: text-center
@@ -270,7 +262,6 @@ class: text-center
270
262
271
263
of writing composable functions
272
264
273
-
274
265
---
275
266
276
267
# What's Composable Functions
@@ -309,7 +300,6 @@ export function useDark(options: UseDarkOptions = {}) {
309
300
<VueUse name =" useDark " />
310
301
</div >
311
302
312
-
313
303
---
314
304
315
305
# Think as "Connections"
@@ -327,7 +317,6 @@ The `setup()` only runs **once** on component initialization, to construct the r
327
317
</div >
328
318
</div >
329
319
330
-
331
320
---
332
321
333
322
# One Thing at a Time
@@ -340,7 +329,6 @@ Just the same as authoring JavaScript functions.
340
329
- Keep function small and simple
341
330
- "Do one thing, and do it well"
342
331
343
-
344
332
---
345
333
346
334
# Passing Refs as Arguments <MarkerPattern />
@@ -359,7 +347,6 @@ Just the same as authoring JavaScript functions.
359
347
Plain function
360
348
</div >
361
349
362
-
363
350
``` ts
364
351
function add(a : number , b : number ) {
365
352
return a + b
@@ -416,7 +403,6 @@ c.value // 6
416
403
417
404
</div >
418
405
419
-
420
406
---
421
407
422
408
# MaybeRef <MarkerTips />
@@ -431,7 +417,6 @@ type MaybeRef<T> = Ref<T> | T
431
417
432
418
In VueUse, we use this helper heavily to support optional reactive arguments
433
419
434
-
435
420
` ` ` ts
436
421
export function useTimeAgo(
437
422
time : Date | number | string | Ref <Date | number | string >,
@@ -455,7 +440,6 @@ export function useTimeAgo(
455
440
456
441
</v-click >
457
442
458
-
459
443
---
460
444
461
445
# Make it Flexible <MarkerPattern />
@@ -501,7 +485,6 @@ name.value = 'Hi' // Hi - World
501
485
<VueUse name =" useTitle " />
502
486
</div >
503
487
504
-
505
488
---
506
489
507
490
# ` useTitle ` <Marker class =" text-blue-400 " >Case</Marker >
@@ -531,11 +514,6 @@ export function useTitle(
531
514
532
515
``` html
533
516
534
-
535
-
536
-
537
-
538
-
539
517
<-- 1. use the user provided ref or create a new one
540
518
541
519
<-- 2. sync ref changes to the document title
@@ -545,7 +523,6 @@ export function useTitle(
545
523
</v-clicks >
546
524
</div >
547
525
548
-
549
526
---
550
527
551
528
# "Reuse" Ref <MarkerCore />
@@ -561,7 +538,6 @@ const bar = ref(foo) // Ref<1>
561
538
foo === bar // true
562
539
```
563
540
564
-
565
541
``` ts
566
542
function useFoo(foo : Ref <string > | string ) {
567
543
// no need!
@@ -578,7 +554,6 @@ Extremely useful in composable functions that take uncertain argument types.
578
554
579
555
</v-clicks >
580
556
581
-
582
557
---
583
558
584
559
# ` ref ` / ` unref ` <MarkerTips />
@@ -602,7 +577,6 @@ function useBala<T>(arg: MaybeRef<T>) {
602
577
603
578
</div >
604
579
605
-
606
580
---
607
581
608
582
# Object of Refs <MarkerPattern />
@@ -639,7 +613,6 @@ mouse.x === x.value // true
639
613
</v-clicks >
640
614
</div >
641
615
642
-
643
616
---
644
617
645
618
# Async to "Sync" <MarkerTips />
@@ -674,7 +647,6 @@ Establish the "Connections" first, then wait for data to be filled up. The idea
674
647
675
648
</div >
676
649
677
-
678
650
---
679
651
680
652
# ` useFetch ` <Marker class =" text-blue-400 " >Case</Marker >
@@ -704,7 +676,6 @@ export function useFetch<R>(url: MaybeRef<string>) {
704
676
<VueUse name =" useFetch " />
705
677
</div >
706
678
707
-
708
679
---
709
680
710
681
# Side-effects Self Cleanup <MarkerPattern />
@@ -758,7 +729,6 @@ const scope = effectScope(() => {
758
729
stop (scope )
759
730
```
760
731
761
-
762
732
---
763
733
disabled: true
764
734
---
@@ -793,7 +763,6 @@ export default defineComponent({
793
763
794
764
</div >
795
765
796
-
797
766
---
798
767
disabled: true
799
768
---
@@ -827,7 +796,6 @@ export default defineComponent({
827
796
</v-click >
828
797
</div >
829
798
830
-
831
799
---
832
800
833
801
# Typed Provide / Inject <MarkerCore />
@@ -850,7 +818,6 @@ export const injectKeyUser: InjectionKey<UserInfo> = Symbol('user')
850
818
851
819
</div >
852
820
853
-
854
821
---
855
822
856
823
# Typed Provide / Inject <MarkerCore />
@@ -894,7 +861,6 @@ export default {
894
861
</v-clicks >
895
862
</div >
896
863
897
-
898
864
---
899
865
900
866
# Shared State <MarkerPattern />
@@ -940,7 +906,6 @@ console.log(state.foo) // 2
940
906
941
907
<h3 v-click class =" opacity-100 " >⚠️ But it's not SSR compatible!</h3 >
942
908
943
-
944
909
---
945
910
946
911
# Shared State (SSR friendly) <MarkerPattern />
@@ -1001,7 +966,6 @@ const state = useMyState()
1001
966
1002
967
</div >
1003
968
1004
-
1005
969
---
1006
970
1007
971
# useVModel <MarkerTips />
@@ -1061,7 +1025,6 @@ export default defineComponent({
1061
1025
<VueUse name =" useVModel " />
1062
1026
</div >
1063
1027
1064
-
1065
1028
---
1066
1029
disabled: true
1067
1030
---
@@ -1093,14 +1056,12 @@ export function usePassiveVModel(props, name) {
1093
1056
1094
1057
</v-click >
1095
1058
1096
-
1097
1059
---
1098
1060
layout: center
1099
1061
---
1100
1062
1101
1063
# All of them work for both Vue 2 and 3
1102
1064
1103
-
1104
1065
---
1105
1066
1106
1067
# ` @vue/composition-api ` <Marker class =" text-teal-400 " >Lib</Marker >
@@ -1118,7 +1079,6 @@ Vue.use(VueCompositionAPI)
1118
1079
import { reactive , ref } from ' @vue/composition-api'
1119
1080
```
1120
1081
1121
-
1122
1082
---
1123
1083
1124
1084
# Vue 2.7 <Marker class =" text-purple-400 " >Upcoming</Marker >
@@ -1131,7 +1091,6 @@ import { reactive, ref } from '@vue/composition-api'
1131
1091
- IE11 support.
1132
1092
- LTS.
1133
1093
1134
-
1135
1094
---
1136
1095
1137
1096
# Vue Demi <Marker class =" text-teal-400 " >Lib</Marker >
@@ -1145,7 +1104,6 @@ import { defineComponent, reactive, ref } from 'vue-demi'
1145
1104
1146
1105
<img class =" h-50 mx-auto " src =" https://cdn.jsdelivr.net/gh/vueuse/vue-demi/assets/banner.png " alt =" " />
1147
1106
1148
-
1149
1107
---
1150
1108
1151
1109
# Recap
@@ -1159,7 +1117,6 @@ import { defineComponent, reactive, ref } from 'vue-demi'
1159
1117
- Side-effect self clean up
1160
1118
- Shared state
1161
1119
1162
-
1163
1120
---
1164
1121
layout: center
1165
1122
class: 'text-center pb-5 :'
0 commit comments