yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
63 lines (62 loc) • 1.52 kB
JavaScript
import { defineComponent, ref, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock } from "vue";
import Player from "xgplayer";
const _sfc_main = defineComponent({
name: "EleXgPlayer",
props: {
config: {
type: Object,
required: true
}
},
emits: {
player: (_player) => true
},
setup(props, { emit }) {
let player = null;
const rootRef = ref(null);
const init = () => {
var _a;
destroy();
if (rootRef.value && ((_a = props.config) == null ? void 0 : _a.url)) {
player = new Player(
Object.assign({}, props.config, { el: rootRef.value })
);
emit("player", player);
}
};
const destroy = () => {
if (player && typeof player.destroy === "function") {
player.destroy();
player = null;
}
};
onMounted(() => {
init();
});
onBeforeUnmount(() => {
destroy();
});
watch(
() => props.config,
() => {
init();
}
);
return { rootRef, player };
}
});
const _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
const _hoisted_1 = { ref: "rootRef" };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", _hoisted_1, null, 512);
}
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
index as default
};