0
0

index.iife.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
  2. if (VueDemi.install) {
  3. return VueDemi
  4. }
  5. if (!Vue) {
  6. console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
  7. return VueDemi
  8. }
  9. // Vue 2.7
  10. if (Vue.version.slice(0, 4) === '2.7.') {
  11. for (var key in Vue) {
  12. VueDemi[key] = Vue[key]
  13. }
  14. VueDemi.isVue2 = true
  15. VueDemi.isVue3 = false
  16. VueDemi.install = function () {}
  17. VueDemi.Vue = Vue
  18. VueDemi.Vue2 = Vue
  19. VueDemi.version = Vue.version
  20. VueDemi.warn = Vue.util.warn
  21. function createApp(rootComponent, rootProps) {
  22. var vm
  23. var provide = {}
  24. var app = {
  25. config: Vue.config,
  26. use: Vue.use.bind(Vue),
  27. mixin: Vue.mixin.bind(Vue),
  28. component: Vue.component.bind(Vue),
  29. provide: function (key, value) {
  30. provide[key] = value
  31. return this
  32. },
  33. directive: function (name, dir) {
  34. if (dir) {
  35. Vue.directive(name, dir)
  36. return app
  37. } else {
  38. return Vue.directive(name)
  39. }
  40. },
  41. mount: function (el, hydrating) {
  42. if (!vm) {
  43. vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
  44. vm.$mount(el, hydrating)
  45. return vm
  46. } else {
  47. return vm
  48. }
  49. },
  50. unmount: function () {
  51. if (vm) {
  52. vm.$destroy()
  53. vm = undefined
  54. }
  55. },
  56. }
  57. return app
  58. }
  59. VueDemi.createApp = createApp
  60. }
  61. // Vue 2.6.x
  62. else if (Vue.version.slice(0, 2) === '2.') {
  63. if (VueCompositionAPI) {
  64. for (var key in VueCompositionAPI) {
  65. VueDemi[key] = VueCompositionAPI[key]
  66. }
  67. VueDemi.isVue2 = true
  68. VueDemi.isVue3 = false
  69. VueDemi.install = function () {}
  70. VueDemi.Vue = Vue
  71. VueDemi.Vue2 = Vue
  72. VueDemi.version = Vue.version
  73. } else {
  74. console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
  75. }
  76. }
  77. // Vue 3
  78. else if (Vue.version.slice(0, 2) === '3.') {
  79. for (var key in Vue) {
  80. VueDemi[key] = Vue[key]
  81. }
  82. VueDemi.isVue2 = false
  83. VueDemi.isVue3 = true
  84. VueDemi.install = function () {}
  85. VueDemi.Vue = Vue
  86. VueDemi.Vue2 = undefined
  87. VueDemi.version = Vue.version
  88. VueDemi.set = function (target, key, val) {
  89. if (Array.isArray(target)) {
  90. target.length = Math.max(target.length, key)
  91. target.splice(key, 1, val)
  92. return val
  93. }
  94. target[key] = val
  95. return val
  96. }
  97. VueDemi.del = function (target, key) {
  98. if (Array.isArray(target)) {
  99. target.splice(key, 1)
  100. return
  101. }
  102. delete target[key]
  103. }
  104. } else {
  105. console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
  106. }
  107. return VueDemi
  108. })(
  109. (this.VueDemi = this.VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
  110. this.Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
  111. this.VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
  112. );