create-page.js 856 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
import {
  hasOwn
3
} from 'uni-shared'
fxy060608's avatar
fxy060608 已提交
4

5
export default function createPage (pageVm, options) {
fxy060608's avatar
fxy060608 已提交
6 7
  const $route = pageVm.$route
  pageVm.route = $route.meta.pagePath
8 9 10
  if (!pageVm.options) { // 可能开发者会声明 options 属性
    pageVm.options = options
  }
fxy060608's avatar
fxy060608 已提交
11 12

  const id = hasOwn($route.params, '__id__') ? $route.params.__id__ : $route.meta.id
fxy060608's avatar
fxy060608 已提交
13
  pageVm.__page__ = {
fxy060608's avatar
fxy060608 已提交
14
    id,
fxy060608's avatar
fxy060608 已提交
15 16
    path: $route.path,
    route: $route.meta.pagePath,
17
    fullPath: $route.meta.isEntry ? $route.meta.pagePath : $route.fullPath,
18
    options: options,
fxy060608's avatar
fxy060608 已提交
19 20
    meta: Object.assign({}, $route.meta)
  }
21 22
  // 兼容 mpvue
  pageVm.$vm = pageVm
fxy060608's avatar
fxy060608 已提交
23
  pageVm.$root = pageVm
fxy060608's avatar
fxy060608 已提交
24
  pageVm.$holder = pageVm.$parent.$parent
25 26 27 28 29 30 31 32
  // 补充 mp 相关属性
  pageVm.$mp = {
    mpType: 'page',
    page: pageVm,
    query: {},
    // 暂不支持
    status: ''
  }
fxy060608's avatar
fxy060608 已提交
33
}