市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

  1. /* eslint-disable new-cap */
  2. import * as Vue from 'vue'
  3. import App from 'virtual:vue-inspector-path:Overlay.vue'
  4. import inspectorOptions from 'virtual:vue-inspector-options'
  5. const CONTAINER_ID = 'vue-inspector-container'
  6. function createInspectorContainer() {
  7. if (document.getElementById(CONTAINER_ID) != null)
  8. throw new Error('vueInspectorContainer element already exists')
  9. const el = document.createElement('div')
  10. el.setAttribute('id', CONTAINER_ID)
  11. document.getElementsByTagName('body')[0].appendChild(el)
  12. return el
  13. }
  14. function load() {
  15. const isClient = typeof window !== 'undefined'
  16. if (!isClient)
  17. return
  18. createInspectorContainer()
  19. const { vue } = inspectorOptions
  20. // vue 2/3 compatibility
  21. vue === 3
  22. ? Vue.createApp({
  23. render: () => Vue.h(App),
  24. devtools: {
  25. hide: true,
  26. },
  27. }).mount(`#${CONTAINER_ID}`)
  28. : new Vue.default({
  29. render: h => h(App),
  30. devtools: {
  31. hide: true,
  32. },
  33. }).$mount(`#${CONTAINER_ID}`)
  34. }
  35. if (inspectorOptions.lazyLoad)
  36. setTimeout(load, inspectorOptions.lazyLoad)
  37. else
  38. load()