feat: add React and Vue usage examples to documentation

This commit is contained in:
Harvey Zhao committed 2026-01-04 16:28:42 +08:00
1 parent d9ac20b3f1
commit 6370f607f8
1 file changed
+63 -2
+63 -2
View File
@@ -98,6 +98,69 @@ let art = new Artplayer({
})
```
## React
```jsx
import Artplayer from 'artplayer'
import { useEffect, useRef } from 'react'
export default function Player({ option, getInstance, ...rest }) {
const $container = useRef()
useEffect(() => {
const art = new Artplayer({
...option,
container: $container.current,
})
if (typeof getInstance === 'function') {
getInstance(art)
}
return () => art.destroy(false)
}, [])
return <div ref={$container} {...rest}></div>
}
```
## Vue
```vue
<template>
<div ref="$container" />
</template>
<script setup>
import Artplayer from 'artplayer'
import { onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
const props = defineProps({
option: {
type: Object,
required: true,
},
})
const emit = defineEmits(['getInstance'])
const art = shallowRef(null)
const $container = ref(null)
onMounted(() => {
art.value = new Artplayer({
...props.option,
container: $container.value,
})
emit('getInstance', art.value)
})
onBeforeUnmount(() => {
art.value.destroy(false)
})
</script>
```
## Plugins
| Name | Describe | State |
@@ -159,8 +222,6 @@ We accept donations through these channels:
![QQ Group](./images/qqgroup.png)
[![Powered by DartNode](https://dartnode.com/branding/DN-Open-Source-sm.png)](https://dartnode.com 'Powered by DartNode - Free VPS for Open Source')
## License
MIT © Harvey Zack