vue.js 1.4 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
// 目前仅支持 store, use, mixin, component, prototype
fxy060608's avatar
fxy060608 已提交
2

3 4 5 6
let store
const mixins = []
const plugins = []
const components = []
fxy060608's avatar
fxy060608 已提交
7

fxy060608's avatar
fxy060608 已提交
8
// fake
fxy060608's avatar
fxy060608 已提交
9 10
function Vue (options) {
  if (options && options.store) {
11
    store = options.store
fxy060608's avatar
fxy060608 已提交
12 13 14
  }
}

fxy060608's avatar
fxy060608 已提交
15 16 17 18
Vue.prototype.$mount = function () {}

Vue.config = {}

fxy060608's avatar
fxy060608 已提交
19
Vue.use = function (plugin) {
fxy060608's avatar
fxy060608 已提交
20 21 22 23 24 25 26 27 28
  const isVuex = plugin.Store && plugin.mapState
  if (isVuex) {
    const exports = {}
    /* eslint-disable no-undef */
    context.VueFactory(exports, {} /* document */, {} /* quickappHelper */)
    plugin.install(exports.Vue)
  } else {
    plugins.push(plugin)
  }
fxy060608's avatar
fxy060608 已提交
29 30 31
}

Vue.mixin = function (mixin) {
32 33 34 35 36 37 38 39
  mixins.push(mixin)
}

Vue.component = function (id, definition) {
  components.push({
    id,
    definition
  })
fxy060608's avatar
fxy060608 已提交
40 41
}

42 43 44
const injectRef = Object.getPrototypeOf(global) || global

injectRef.__VuePlugin = {
fxy060608's avatar
fxy060608 已提交
45
  install (PageVue, options) {
46
    mixins.forEach(mixin => {
fxy060608's avatar
fxy060608 已提交
47
      PageVue.mixin(mixin)
48 49 50
    })

    plugins.forEach(plugin => {
fxy060608's avatar
fxy060608 已提交
51
      PageVue.use(plugin)
52
    })
fxy060608's avatar
fxy060608 已提交
53

54 55 56 57
    components.forEach(({
      id,
      definition
    }) => {
fxy060608's avatar
fxy060608 已提交
58 59 60 61 62 63 64
      PageVue.component(id, definition)
    })

    Object.keys(Vue.prototype).forEach(name => {
      if (name !== '$mount') {
        PageVue.prototype[name] = Vue.prototype[name]
      }
65
    })
fxy060608's avatar
fxy060608 已提交
66

fxy060608's avatar
fxy060608 已提交
67
    store && (PageVue.prototype.$store = store)
68 69
  }
}
fxy060608's avatar
fxy060608 已提交
70 71

export default Vue