create-app.js 966 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6
import Vue from 'vue'

import 'uni-platform/runtime/index'

import EventChannel from 'uni-helpers/EventChannel'

fxy060608's avatar
fxy060608 已提交
7
import parseApp from 'uni-platform/runtime/wrapper/app-parser'
fxy060608's avatar
fxy060608 已提交
8

fxy060608's avatar
fxy060608 已提交
9 10 11 12
import {
  getEventChannel
} from 'uni-helpers/navigate-to'

fxy060608's avatar
fxy060608 已提交
13
export default function createApp (vm) {
fxy060608's avatar
fxy060608 已提交
14
  Vue.prototype.getOpenerEventChannel = function () {
15 16 17
    // 微信小程序使用自身getOpenerEventChannel
    if (__PLATFORM__ === 'mp-weixin') {
      return this.$scope.getOpenerEventChannel()
fxy060608's avatar
fxy060608 已提交
18
    }
19 20 21 22
    if (!this.__eventChannel__) {
      this.__eventChannel__ = new EventChannel()
    }
    return this.__eventChannel__
fxy060608's avatar
fxy060608 已提交
23 24 25 26 27 28 29 30 31
  }
  const callHook = Vue.prototype.__call_hook
  Vue.prototype.__call_hook = function (hook, args) {
    if (hook === 'onLoad' && args && args.__id__) {
      this.__eventChannel__ = getEventChannel(args.__id__)
      delete args.__id__
    }
    return callHook.call(this, hook, args)
  }
fxy060608's avatar
fxy060608 已提交
32
  App(parseApp(vm))
33
  return vm
34
}