UNPKG

yuang-framework-ui-pc

Version:

yuang-framework-ui-pc Library

62 lines (61 loc) 1.47 kB
"use strict"; const vue = require("vue"); const Player = require("xgplayer"); const _sfc_main = vue.defineComponent({ name: "EleXgPlayer", props: { config: { type: Object, required: true } }, emits: { player: (_player) => true }, setup(props, { emit }) { let player = null; const rootRef = vue.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; } }; vue.onMounted(() => { init(); }); vue.onBeforeUnmount(() => { destroy(); }); vue.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 vue.openBlock(), vue.createElementBlock("div", _hoisted_1, null, 512); } const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); module.exports = index;