installComponents.js 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. global.installComponents = function (component, components) {
  2. var options = typeof component.exports === 'function'
  3. ? component.exports.extendOptions
  4. : component.options
  5. if (typeof component.exports === 'function') {
  6. options.components = component.exports.options.components
  7. }
  8. options.components = options.components || {}
  9. for (var i in components) {
  10. options.components[i] = options.components[i] || components[i]
  11. }
  12. if (options.functional) {
  13. provideFunctionalComponents(component, options.components)
  14. }
  15. }
  16. var functionalPatchKey = '_functionalComponents'
  17. function provideFunctionalComponents(component, components) {
  18. if (component.exports[functionalPatchKey]) {
  19. return
  20. }
  21. component.exports[functionalPatchKey] = true
  22. var render = component.exports.render
  23. component.exports.render = function (h, vm) {
  24. return render(h, Object.assign({}, vm, {
  25. _c: function (n, a, b) {
  26. return vm._c(components[n] || n, a, b)
  27. }
  28. }))
  29. }
  30. }