qiankun.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * @Author: sjl
  3. * @Date: 2023-04-25 17:47:52
  4. * @Descripttion:
  5. */
  6. import { createApp } from 'vue'
  7. import '@/assets/style.css'
  8. import App from './App.vue'
  9. import { createWebHistory } from 'vue-router'
  10. import createRouter from "./router"
  11. import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
  12. let router: any = null
  13. let instance: any = null
  14. let history: any = null
  15. function render(props: any | undefined) {
  16. console.log("__POWERED_BY_QIANKUN__", qiankunWindow.__POWERED_BY_QIANKUN__)
  17. const container = props ? props.container : undefined
  18. history = createWebHistory(qiankunWindow.__POWERED_BY_QIANKUN__ ? '/two' : '/ms-two')
  19. router = createRouter(history)
  20. instance = createApp(App)
  21. instance.use(router)
  22. instance.mount(container ? container.querySelector('#app') : '#app')
  23. }
  24. renderWithQiankun({
  25. mount(props: any) {
  26. render(props)
  27. instance.config.globalProperties.$onGlobalStateChange = props.onGlobalStateChange
  28. instance.config.globalProperties.$setGlobalState = props.setGlobalState
  29. },
  30. bootstrap() {
  31. console.log('%c%s', 'color: green;', 'vue3.0 app bootstraped')
  32. },
  33. unmount() {
  34. instance.unmount()
  35. instance._container.innerHTML = ''
  36. instance = null
  37. router = null
  38. history.destroy()
  39. },
  40. update() {
  41. console.log('update')
  42. }
  43. })
  44. if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  45. render(undefined)
  46. }