main.js 1008 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import Vant from 'vant'
  5. import 'vant/lib/index.css'
  6. import './assets/main.css'
  7. import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
  8. let instance = null
  9. function render(props = {}) {
  10. const { container } = props
  11. instance = createApp(App)
  12. instance.provide('microProps', props)
  13. instance.use(router)
  14. instance.use(Vant) // 移动端 UI 组件库 Vant
  15. instance.mount(container ? container.querySelector('#app') : document.getElementById('app'))
  16. }
  17. renderWithQiankun({
  18. bootstrap() {
  19. console.log('[mobile-app] bootstrap')
  20. },
  21. mount(props) {
  22. console.log('[mobile-app] mount', props)
  23. render(props)
  24. },
  25. update(props) {
  26. console.log('[mobile-app] update', props)
  27. },
  28. unmount() {
  29. console.log('[mobile-app] unmount')
  30. instance?.unmount()
  31. instance = null
  32. },
  33. })
  34. // 独立运行时直接渲染
  35. if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  36. render()
  37. }