index.js 1.3 KB
Newer Older
fxy060608's avatar
init v3  
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import initVue from 'uni-core/vue'

import {
  registerApp
} from '../app'

import {
  initData
} from './data'

import {
  initLifecycle
} from './lifecycle'

fxy060608's avatar
fxy060608 已提交
15 16 17 18
import {
  vdSyncCallbacks
} from '../subscribe-handlers/on-vd-sync-callback'

fxy060608's avatar
init v3  
fxy060608 已提交
19 20 21 22 23 24 25
export default {
  install (Vue, options) {
    initVue(Vue)

    initData(Vue)
    initLifecycle(Vue)

26 27 28 29 30
    Object.defineProperty(Vue.prototype, '$page', {
      get () {
        return this.$root.$scope.$page
      }
    })
fxy060608's avatar
fxy060608 已提交
31 32 33 34 35 36 37 38
    // 兼容旧版本
    Object.defineProperty(Vue.prototype, '$mp', {
      get () {
        return {
          page: this.$root.$scope.$page
        }
      }
    })
39

fxy060608's avatar
init v3  
fxy060608 已提交
40 41 42 43 44 45 46 47
    const oldMount = Vue.prototype.$mount
    Vue.prototype.$mount = function mount (el, hydrating) {
      if (this.mpType === 'app') {
        this.$options.render = function () {}
        registerApp(this)
      }
      return oldMount.call(this, el, hydrating)
    }
fxy060608's avatar
fxy060608 已提交
48 49 50 51 52 53 54 55 56

    Vue.prototype.$nextTick = function nextTick (cb) {
      const renderWatcher = this._watcher
      if (
        renderWatcher &&
        this._$queue.find(watcher => renderWatcher === watcher)
      ) {
        vdSyncCallbacks.push(cb)
      } else {
fxy060608's avatar
fxy060608 已提交
57 58
        // $nextTick bind vm context
        Vue.nextTick.call(this, cb)
fxy060608's avatar
fxy060608 已提交
59 60
      }
    }
fxy060608's avatar
init v3  
fxy060608 已提交
61 62
  }
}