'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
  stringifyQuery
} from 'uni-shared/query'
 
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)
  })
}
 
export default function parsePage (vuePageOptions) {
  const pageOptions = parseBasePage(vuePageOptions)
 
  // 纠正百度小程序生命周期methods:onShow在methods:onLoad之前触发的问题
  pageOptions.methods.onShow = function onShow () {
    if (this.$vm && this.$vm.$mp.query) {
      this.$vm.__call_hook('onShow')
    }
  }
 
  pageOptions.methods.onLoad = function onLoad (query) {
    // 百度 onLoad 在 attached 之前触发(基础库小于 3.70),先存储 args, 在 attached 里边触发 onLoad
    if (this.$vm) {
      const copyQuery = Object.assign({}, query)
      delete copyQuery.__id__
      this.pageinstance.$page = this.$page = {
        fullPath: '/' + this.pageinstance.route + stringifyQuery(copyQuery)
      }
      this.$vm.$mp.query = query
      this.$vm.__call_hook('onLoad', query)
      this.$vm.__call_hook('onShow')
    } else {
      this.pageinstance._$args = query
    }
  }
 
  pageOptions.methods.onUnload = function onUnload () {
    this.$vm.__call_hook('onUnload')
    onPageUnload(this.$vm)
  }
 
  return pageOptions
}