You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/1.getting-started/3.confetti-tutorial.md
+55-33Lines changed: 55 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,9 @@ useScriptNpm({
88
88
file: 'dist/js-confetti.browser.js',
89
89
version: '0.12.0',
90
90
// tell useScript how to resolve the third-party script
91
-
use: () => typeof window.JSConfetti !== 'undefined' && new window.JSConfetti()
91
+
use() {
92
+
return { JSConfetti: window.JSConfetti }
93
+
},
92
94
})
93
95
</script>
94
96
```
@@ -97,35 +99,44 @@ useScriptNpm({
97
99
98
100
Now that we have a way to resolve the third-party script API, we can start using it.
99
101
100
-
To use the API we have a couple of options proxied functions or awaiting the script load.
102
+
The `js-confetti` library requires us to instantiate a new instance of the `JSConfetti` class everytime it's used,
103
+
the most compatible way to handle this is to for the script to load explicitly.
101
104
102
-
See the [Understanding proxied functions](/docs/guides/script-loading#Understanding-proxied-functions) section for more information.
105
+
However, we can also make use of [proxied functions](/docs/guides/script-loading#Understanding-proxied-functions) if we prefer an easier to use API. Note that this will break
106
+
when switching between pages as `new window.JSConfetti()` needs to be called between pages.
103
107
104
108
::code-group
105
109
106
-
```vue [Proxy Usage]
110
+
```vue [Explicit script Load]
107
111
<script setup lang="ts">
108
-
const { addConfetti } = useScriptNpm({
112
+
const { $script } = useScriptNpm({
109
113
packageName: 'js-confetti',
110
114
file: 'dist/js-confetti.browser.js',
111
115
version: '0.12.0',
112
-
use: () => typeof window.JSConfetti !== 'undefined' && new window.JSConfetti()
0 commit comments