/
App.vue
54 lines (48 loc) 路 1.06 KB
/
App.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
<template>
<div class="buttons">
<button @click="mounted = !mounted">
{{ mounted ? 'Mounted' : 'Unmounted' }}
</button>
<button @click="startFireworks">Start</button>
</div>
<Fireworks
ref="fw"
v-if="mounted"
:autostart="false"
:options="options"
:style="{
top: 0,
left: 0,
width: '100%',
height: '100%',
position: 'fixed',
background: '#000'
}"
/>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue'
import { Fireworks } from '@fireworks-js/vue'
import type { FireworksOptions } from '@fireworks-js/vue'
const fw = ref<InstanceType<typeof Fireworks>>()
const options = ref<FireworksOptions>({ opacity: 0.5 })
const mounted = ref(true)
async function startFireworks() {
if (!fw.value) return
fw.value.start()
await new Promise((resolve) => setTimeout(resolve, 1000))
await fw.value.waitStop()
}
watch(fw, () => startFireworks())
</script>
<style>
body {
background-color: #000;
}
.buttons {
z-index: 1;
position: absolute;
display: flex;
gap: 4px;
}
</style>