page-parser.js 1.2 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import {
Q
qiang 已提交
2
  isPage,
fxy060608's avatar
fxy060608 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  initRelation
} from './util'

import parseBasePage from '../../../mp-weixin/runtime/wrapper/page-base-parser'

function detached ($vm) {
  $vm.$children.forEach(childVm => {
    childVm.$scope.detached()
  })
  $vm.$scope.detached()
}

function onPageUnload ($vm) {
  $vm.$destroy()
  $vm.$children.forEach(childVm => {
    detached(childVm)
  })
}

fxy060608's avatar
fxy060608 已提交
22
export default function parsePage (vuePageOptions) {
fxy060608's avatar
fxy060608 已提交
23 24 25
  const pageOptions = parseBasePage(vuePageOptions, {
    isPage,
    initRelation
Q
qiang 已提交
26 27 28 29 30 31 32
  })

  const newLifecycle = swan.canIUse('lifecycle-2-0')

  // 纠正百度小程序新生命周期(2.0)methods:onShow在methods:onLoad之前触发的问题
  if (newLifecycle) {
    delete pageOptions.methods.onShow
33
  }
fxy060608's avatar
fxy060608 已提交
34 35 36

  pageOptions.methods.onLoad = function onLoad (args) {
    // 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad
Q
qiang 已提交
37 38 39 40 41 42
    if (this.$vm) {
      this.$vm.$mp.query = args
      this.$vm.__call_hook('onLoad', args)
      this.$vm.__call_hook('onShow')
    } else {
      this.pageinstance._$args = args
fxy060608's avatar
fxy060608 已提交
43
    }
fxy060608's avatar
fxy060608 已提交
44 45 46 47 48 49 50 51
  }

  pageOptions.methods.onUnload = function onUnload () {
    this.$vm.__call_hook('onUnload')
    onPageUnload(this.$vm)
  }

  return pageOptions
Q
qiang 已提交
52
}