3350e1a8dd0a128ebdfb37415113f1ca514905ed57d42d2d966a5e9f09aa1734f486b168ddac73ddbba21bde56813fa6b6eac4bc86f04c6bfcae4292f4af39 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* @flow */
  2. import config from '../config'
  3. import { initUse } from './use'
  4. import { initMixin } from './mixin'
  5. import { initExtend } from './extend'
  6. import { initAssetRegisters } from './assets'
  7. import { set, del } from '../observer/index'
  8. import { ASSET_TYPES } from 'shared/constants'
  9. import builtInComponents from '../components/index'
  10. import { observe } from 'core/observer/index'
  11. import {
  12. warn,
  13. extend,
  14. nextTick,
  15. mergeOptions,
  16. defineReactive
  17. } from '../util/index'
  18. export function initGlobalAPI (Vue: GlobalAPI) {
  19. // config
  20. const configDef = {}
  21. configDef.get = () => config
  22. if (process.env.NODE_ENV !== 'production') {
  23. configDef.set = () => {
  24. warn(
  25. 'Do not replace the Vue.config object, set individual fields instead.'
  26. )
  27. }
  28. }
  29. Object.defineProperty(Vue, 'config', configDef)
  30. // exposed util methods.
  31. // NOTE: these are not considered part of the public API - avoid relying on
  32. // them unless you are aware of the risk.
  33. Vue.util = {
  34. warn,
  35. extend,
  36. mergeOptions,
  37. defineReactive
  38. }
  39. Vue.set = set
  40. Vue.delete = del
  41. Vue.nextTick = nextTick
  42. // 2.6 explicit observable API
  43. Vue.observable = <T>(obj: T): T => {
  44. observe(obj)
  45. return obj
  46. }
  47. Vue.options = Object.create(null)
  48. ASSET_TYPES.forEach(type => {
  49. Vue.options[type + 's'] = Object.create(null)
  50. })
  51. // this is used to identify the "base" constructor to extend all plain-object
  52. // components with in Weex's multi-instance scenarios.
  53. Vue.options._base = Vue
  54. extend(Vue.options.components, builtInComponents)
  55. initUse(Vue)
  56. initMixin(Vue)
  57. initExtend(Vue)
  58. initAssetRegisters(Vue)
  59. }