mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
update vue3
This commit is contained in:
1 parent
181121a36d
commit
38ad57192d
1 file changed
+27
-27
@@ -2,35 +2,35 @@
|
||||
<div ref="artRef"></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import Artplayer from 'artplayer';
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
instance: null,
|
||||
};
|
||||
},
|
||||
props: {
|
||||
option: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.instance = new Artplayer({
|
||||
...this.option,
|
||||
container: this.$refs.artRef,
|
||||
});
|
||||
const emit = defineEmits(['get-instance']);
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.$emit('get-instance', this.instance);
|
||||
});
|
||||
const props = defineProps({
|
||||
option: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.instance && this.instance.destroy) {
|
||||
this.instance.destroy(false);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const instance = ref(null);
|
||||
const artRef = ref(null);
|
||||
|
||||
onMounted(() => {
|
||||
instance.value = new Artplayer({
|
||||
...props.option,
|
||||
container: artRef.value,
|
||||
});
|
||||
nextTick(() => {
|
||||
emit('get-instance', instance.value);
|
||||
});
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (instance.value) {
|
||||
instance.value.destroy(false);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user