提交 ad1b719f 编写于 作者: fxy060608's avatar fxy060608

fix(mp-baidu): add $page

上级 65e0f243
import { camelize, isPlainObject, isArray, hasOwn, isFunction, extend } from '@vue/shared';
import { isPlainObject, camelize, isArray, hasOwn, isFunction, extend } from '@vue/shared';
import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
// lifecycle
......@@ -8,6 +8,26 @@ const ON_SHOW$1 = 'onShow';
const ON_LOAD$1 = 'onLoad';
const ON_READY$1 = 'onReady';
const encode$1 = encodeURIComponent;
function stringifyQuery$1(obj, encodeStr = encode$1) {
const res = obj
? Object.keys(obj)
.map((key) => {
let val = obj[key];
if (typeof val === undefined || val === null) {
val = '';
}
else if (isPlainObject(val)) {
val = JSON.stringify(val);
}
return encodeStr(key) + '=' + encodeStr(val);
})
.filter((x) => x.length > 0)
.join('&')
: null;
return res ? `?${res}` : '';
}
class EventChannel$1 {
constructor(id, events) {
this.id = id;
......@@ -1152,15 +1172,21 @@ function parse(pageOptions) {
this.$vm.$callHook(ON_SHOW$1);
}
};
methods.onLoad = function onLoad(args) {
methods.onLoad = function onLoad(query) {
// 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad
if (this.$vm) {
this._$loaded = true;
this.$vm.$callHook(ON_LOAD$1, args);
const copyQuery = extend({}, query);
delete copyQuery.__id__;
this.options = copyQuery;
this.pageinstance.$page = this.$page = {
fullPath: '/' + this.pageinstance.route + stringifyQuery$1(copyQuery),
};
this.$vm.$callHook(ON_LOAD$1, query);
this.$vm.$callHook(ON_SHOW$1);
}
else {
this.pageinstance._$args = args;
this.pageinstance._$args = query;
}
};
}
......
import { extend } from '@vue/shared'
import { MPComponentOptions, MPComponentInstance } from '@dcloudio/uni-mp-core'
import { ON_LOAD, ON_SHOW } from '@dcloudio/uni-shared'
import { ON_LOAD, ON_SHOW, stringifyQuery } from '@dcloudio/uni-shared'
import { parse as parseComponentOptions } from './parseComponentOptions'
......@@ -18,14 +19,24 @@ export function parse(pageOptions: MPComponentOptions) {
}
}
methods.onLoad = function onLoad(this: MPComponentInstance, args) {
methods.onLoad = function onLoad(
this: MPComponentInstance,
query: Record<string, any>
) {
// 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad
if (this.$vm) {
;(this as any)._$loaded = true
this.$vm.$callHook(ON_LOAD, args)
const copyQuery = extend({}, query)
delete copyQuery.__id__
;(this as any).options = copyQuery
;(this as any).pageinstance.$page = (this as any).$page = {
fullPath:
'/' + (this as any).pageinstance.route + stringifyQuery(copyQuery),
}
this.$vm.$callHook(ON_LOAD, query)
this.$vm.$callHook(ON_SHOW)
} else {
;(this as any).pageinstance._$args = args
;(this as any).pageinstance._$args = query
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册