mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
添加react组件
This commit is contained in:
1 parent
f13aebd720
commit
e00fab0bfe
6 files changed
+129
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import React, { Component } from 'react';
|
||||
import Artplayer from 'artplayer';
|
||||
|
||||
export default class ArtplayerComponent extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
Artplayer.utils.errorHandle(
|
||||
props.option && typeof props.option === 'object',
|
||||
"The prop 'option' object cannot be missing",
|
||||
);
|
||||
this.instance = null;
|
||||
this.artRef = React.createRef();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { option, getInstance } = this.props;
|
||||
this.instance = new Artplayer({
|
||||
...option,
|
||||
container: this.artRef,
|
||||
});
|
||||
|
||||
if (getInstance && typeof getInstance === 'function') {
|
||||
getInstance(this.instance);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.instance && this.instance.destroy) {
|
||||
this.instance.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { option, getInstance, ...rest } = this.props;
|
||||
return <div ref={this.artRef} {...rest} />;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user