1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| import { startApp, bus } from 'wujie' import { h, defineComponent, onMounted, getCurrentInstance, onBeforeUnmount } from 'vue' import type { App, PropType } from 'vue' import { Props } from './type' const WuJie = defineComponent({ props: { width: { type: String, default: "" }, height: { type: String, default: "" }, name: { type: String, default: "", required: true }, loading: { type: HTMLElement, default: undefined }, url: { type: String, default: "", required: true }, sync: { type: Boolean, default: undefined }, prefix: { type: Object, default: undefined }, alive: { type: Boolean, default: undefined }, props: { type: Object, default: undefined }, attrs: { type: Object, default: undefined }, replace: { type: Function as PropType<Props['replace']>, default: undefined }, fetch: { type: Function as PropType<Props['fetch']>, default: undefined }, fiber: { type: Boolean, default: undefined }, degrade: { type: Boolean, default: undefined }, plugins: { type: Array as PropType<Props['plugins']>, default: null }, beforeLoad: { type: Function as PropType<Props['beforeLoad']>, default: null }, beforeMount: { type: Function as PropType<Props['beforeMount']>, default: null }, afterMount: { type: Function as PropType<Props['afterMount']>, default: null }, beforeUnmount: { type: Function as PropType<Props['beforeUnmount']>, default: null }, afterUnmount: { type: Function as PropType<Props['afterUnmount']>, default: null }, activated: { type: Function as PropType<Props['activated']>, default: null }, deactivated: { type: Function as PropType<Props['deactivated']>, default: null }, }, setup(props: Props, { emit }) { const instance = getCurrentInstance() const handlerEmit = (event: string, ...args: any[]) => { emit(event, ...args) } onMounted(() => { bus.$onAll(handlerEmit) startApp({ name: props.name, url: props.url, el: instance?.refs.wujie as HTMLElement, loading: props.loading, alive: props.alive, fetch: props.fetch, props: props.props, attrs: props.attrs, replace: props.replace, sync: props.sync, prefix: props.prefix, fiber: props.fiber, degrade: props.degrade, plugins: props.plugins, beforeLoad: props.beforeLoad, beforeMount: props.beforeMount, afterMount: props.afterMount, beforeUnmount: props.beforeUnmount, afterUnmount: props.afterUnmount, activated: props.activated, deactivated: props.deactivated, }) })
onBeforeUnmount(() => { bus.$offAll(handlerEmit) })
return () => h('div', { style: { width: 200, height: 200 }, ref: "wujie" }, '') } })
WuJie.install = (app: App) => { app.component('wujie', WuJie) }
export default WuJie
|