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.

59 lines
1.4 KiB

2 months ago
  1. var VueModule = require('vue')
  2. // get the real Vue https://github.com/vueuse/vue-demi/issues/192
  3. var Vue = VueModule.default || VueModule
  4. exports.Vue = Vue
  5. exports.Vue2 = Vue
  6. exports.isVue2 = true
  7. exports.isVue3 = false
  8. exports.install = function () {}
  9. exports.warn = Vue.util.warn
  10. // createApp polyfill
  11. exports.createApp = function (rootComponent, rootProps) {
  12. var vm
  13. var provide = {}
  14. var app = {
  15. config: Vue.config,
  16. use: Vue.use.bind(Vue),
  17. mixin: Vue.mixin.bind(Vue),
  18. component: Vue.component.bind(Vue),
  19. provide: function (key, value) {
  20. provide[key] = value
  21. return this
  22. },
  23. directive: function (name, dir) {
  24. if (dir) {
  25. Vue.directive(name, dir)
  26. return app
  27. } else {
  28. return Vue.directive(name)
  29. }
  30. },
  31. mount: function (el, hydrating) {
  32. if (!vm) {
  33. vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
  34. vm.$mount(el, hydrating)
  35. return vm
  36. } else {
  37. return vm
  38. }
  39. },
  40. unmount: function () {
  41. if (vm) {
  42. vm.$destroy()
  43. vm = undefined
  44. }
  45. },
  46. }
  47. return app
  48. }
  49. Object.keys(VueModule).forEach(function (key) {
  50. exports[key] = VueModule[key]
  51. })
  52. // Not implemented https://github.com/vuejs/core/pull/8111, falls back to getCurrentInstance()
  53. exports.hasInjectionContext = function() {
  54. return !!VueModule.getCurrentInstance()
  55. }