mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 09:33:21 -08:00
feat: add React and Vue usage examples to documentation
This commit is contained in:
1 parent
d9ac20b3f1
commit
6370f607f8
1 file changed
+63
-2
@@ -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
|
## Plugins
|
||||||
|
|
||||||
| Name | Describe | State |
|
| Name | Describe | State |
|
||||||
@@ -159,8 +222,6 @@ We accept donations through these channels:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
[](https://dartnode.com 'Powered by DartNode - Free VPS for Open Source')
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT © Harvey Zack
|
MIT © Harvey Zack
|
||||||
Reference in new issue
Block a user