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

chore(mp): build

上级 16f7cbd1
......@@ -122,19 +122,56 @@ function initMocks(instance, mpInstance, mocks) {
});
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
const ON_HIDE = 'onHide';
//App
const ON_LAUNCH = 'onLaunch';
const ON_ERROR = 'onError';
const ON_THEME_CHANGE = 'onThemeChange';
const ON_PAGE_NOT_FOUND = 'onPageNotFound';
const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
//Page
const ON_LOAD = 'onLoad';
const ON_READY = 'onReady';
const ON_UNLOAD = 'onUnload';
const ON_RESIZE = 'onResize';
const ON_BACK_PRESS = 'onBackPress';
const ON_TAB_ITEM_TAP = 'onTabItemTap';
const ON_REACH_BOTTOM = 'onReachBottom';
const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
const PAGE_HOOKS = [
'onLoad',
'onShow',
// 'onReady', // lifetimes.ready
'onHide',
'onUnload',
'onResize',
// 'onPageScroll', // 影响性能,开发者手动注册
'onTabItemTap',
'onReachBottom',
'onPullDownRefresh',
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'onAddToFavorites',
ON_LOAD,
ON_SHOW,
ON_HIDE,
ON_UNLOAD,
ON_RESIZE,
ON_TAB_ITEM_TAP,
ON_REACH_BOTTOM,
ON_PULL_DOWN_REFRESH,
ON_ADD_TO_FAVORITES,
];
function findHooks(vueOptions, hooks = new Set()) {
if (vueOptions) {
......@@ -162,7 +199,7 @@ function initHook(mpOptions, hook, excludes) {
};
}
}
const EXCLUDE_HOOKS = ['onReady'];
const EXCLUDE_HOOKS = [ON_READY];
function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
hooks.forEach((hook) => initHook(mpOptions, hook, excludes));
}
......@@ -171,12 +208,12 @@ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
}
const HOOKS = [
'onShow',
'onHide',
'onError',
'onThemeChange',
'onPageNotFound',
'onUnhandledRejection',
ON_SHOW,
ON_HIDE,
ON_ERROR,
ON_THEME_CHANGE,
ON_PAGE_NOT_FOUND,
ON_UNHANDLE_REJECTION,
];
function parseApp(instance, parseAppOptions) {
const internalInstance = instance.$;
......@@ -195,7 +232,7 @@ function parseApp(instance, parseAppOptions) {
slots: [],
});
ctx.globalData = this.globalData;
instance.$callHook('onLaunch', options);
instance.$callHook(ON_LAUNCH, options);
},
};
const vueOptions = instance.$.type;
......@@ -216,26 +253,6 @@ function initCreateApp(parseAppOptions) {
};
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
......@@ -870,7 +887,7 @@ function initChildVues(mpInstance) {
}
initChildVues(childMPInstance);
childMPInstance.$vm.$callHook('mounted');
childMPInstance.$vm.$callHook('onReady');
childMPInstance.$vm.$callHook(ON_READY);
});
}
delete mpInstance._$childVues;
......@@ -977,23 +994,23 @@ function createPage(vueOptions) {
// 初始化 vue 实例
this.$vm = createVueComponent('page', this, vueOptions);
initSpecialMethods(this);
this.$vm.$callHook('onLoad', query);
this.$vm.$callHook(ON_LOAD, query);
},
onReady() {
initChildVues(this);
this.$vm.$callHook('mounted');
this.$vm.$callHook('onReady');
this.$vm.$callHook(ON_READY);
},
onUnload() {
if (this.$vm) {
this.$vm.$callHook('onUnload');
this.$vm.$callHook(ON_UNLOAD);
$destroyComponent(this.$vm);
}
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack() {
this.$vm.$callHook('onBackPress');
this.$vm.$callHook(ON_BACK_PRESS);
},
},
__r: handleRef,
......
......@@ -113,19 +113,55 @@ function initMocks(instance, mpInstance, mocks) {
});
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
const ON_HIDE = 'onHide';
//App
const ON_LAUNCH = 'onLaunch';
const ON_ERROR = 'onError';
const ON_THEME_CHANGE = 'onThemeChange';
const ON_PAGE_NOT_FOUND = 'onPageNotFound';
const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
//Page
const ON_LOAD = 'onLoad';
const ON_READY = 'onReady';
const ON_UNLOAD = 'onUnload';
const ON_RESIZE = 'onResize';
const ON_TAB_ITEM_TAP = 'onTabItemTap';
const ON_REACH_BOTTOM = 'onReachBottom';
const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
const PAGE_HOOKS = [
'onLoad',
'onShow',
// 'onReady', // lifetimes.ready
'onHide',
'onUnload',
'onResize',
// 'onPageScroll', // 影响性能,开发者手动注册
'onTabItemTap',
'onReachBottom',
'onPullDownRefresh',
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'onAddToFavorites',
ON_LOAD,
ON_SHOW,
ON_HIDE,
ON_UNLOAD,
ON_RESIZE,
ON_TAB_ITEM_TAP,
ON_REACH_BOTTOM,
ON_PULL_DOWN_REFRESH,
ON_ADD_TO_FAVORITES,
];
function findHooks(vueOptions, hooks = new Set()) {
if (vueOptions) {
......@@ -153,7 +189,7 @@ function initHook$1(mpOptions, hook, excludes) {
};
}
}
const EXCLUDE_HOOKS = ['onReady'];
const EXCLUDE_HOOKS = [ON_READY];
function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
hooks.forEach((hook) => initHook$1(mpOptions, hook, excludes));
}
......@@ -162,12 +198,12 @@ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
}
const HOOKS = [
'onShow',
'onHide',
'onError',
'onThemeChange',
'onPageNotFound',
'onUnhandledRejection',
ON_SHOW,
ON_HIDE,
ON_ERROR,
ON_THEME_CHANGE,
ON_PAGE_NOT_FOUND,
ON_UNHANDLE_REJECTION,
];
function parseApp(instance, parseAppOptions) {
const internalInstance = instance.$;
......@@ -186,7 +222,7 @@ function parseApp(instance, parseAppOptions) {
slots: [],
});
ctx.globalData = this.globalData;
instance.$callHook('onLaunch', options);
instance.$callHook(ON_LAUNCH, options);
},
};
const vueOptions = instance.$.type;
......@@ -207,26 +243,6 @@ function initCreateApp(parseAppOptions) {
};
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
function initBehavior(options) {
return Behavior(options);
}
......@@ -803,7 +819,7 @@ function parsePage(vueOptions, parseOptions) {
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
};
return this.$vm && this.$vm.$callHook('onLoad', query);
return this.$vm && this.$vm.$callHook(ON_LOAD, query);
};
initHooks(methods, PAGE_HOOKS);
initUnknownHooks(methods, vueOptions);
......@@ -843,7 +859,7 @@ function initHook(name, options) {
}
}
Page = function (options) {
initHook('onLoad', options);
initHook(ON_LOAD, options);
return MPPage(options);
};
Component = function (options) {
......@@ -857,7 +873,7 @@ function parse$2(appOptions) {
if (!this.$vm) {
this.onLaunch(args);
}
this.$vm.$callHook('onShow', args);
this.$vm.$callHook(ON_SHOW, args);
};
}
......@@ -898,7 +914,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
if (this.$vm) {
this.$vm.$callHook('mounted');
this.$vm.$callHook('onReady');
this.$vm.$callHook(ON_READY);
}
},
detached() {
......@@ -945,8 +961,8 @@ function parse$1(componentOptions) {
const pageInstance = this.pageinstance;
pageInstance.$vm = this.$vm;
if (hasOwn(pageInstance, '_$args')) {
this.$vm.$callHook('onLoad', pageInstance._$args);
this.$vm.$callHook('onShow');
this.$vm.$callHook(ON_LOAD, pageInstance._$args);
this.$vm.$callHook(ON_SHOW);
delete pageInstance._$args;
}
}
......@@ -983,15 +999,15 @@ function parse(pageOptions) {
// 纠正百度小程序生命周期methods:onShow在methods:onLoad之前触发的问题
methods.onShow = function onShow() {
if (this.$vm && this._$loaded) {
this.$vm.$callHook('onShow');
this.$vm.$callHook(ON_SHOW);
}
};
methods.onLoad = function onLoad(args) {
// 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad
if (this.$vm) {
this._$loaded = true;
this.$vm.$callHook('onLoad', args);
this.$vm.$callHook('onShow');
this.$vm.$callHook(ON_LOAD, args);
this.$vm.$callHook(ON_SHOW);
}
else {
this.pageinstance._$args = args;
......
......@@ -113,19 +113,55 @@ function initMocks(instance, mpInstance, mocks) {
});
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
const ON_HIDE = 'onHide';
//App
const ON_LAUNCH = 'onLaunch';
const ON_ERROR = 'onError';
const ON_THEME_CHANGE = 'onThemeChange';
const ON_PAGE_NOT_FOUND = 'onPageNotFound';
const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
//Page
const ON_LOAD = 'onLoad';
const ON_READY = 'onReady';
const ON_UNLOAD = 'onUnload';
const ON_RESIZE = 'onResize';
const ON_TAB_ITEM_TAP = 'onTabItemTap';
const ON_REACH_BOTTOM = 'onReachBottom';
const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
const PAGE_HOOKS = [
'onLoad',
'onShow',
// 'onReady', // lifetimes.ready
'onHide',
'onUnload',
'onResize',
// 'onPageScroll', // 影响性能,开发者手动注册
'onTabItemTap',
'onReachBottom',
'onPullDownRefresh',
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'onAddToFavorites',
ON_LOAD,
ON_SHOW,
ON_HIDE,
ON_UNLOAD,
ON_RESIZE,
ON_TAB_ITEM_TAP,
ON_REACH_BOTTOM,
ON_PULL_DOWN_REFRESH,
ON_ADD_TO_FAVORITES,
];
function findHooks(vueOptions, hooks = new Set()) {
if (vueOptions) {
......@@ -153,7 +189,7 @@ function initHook$1(mpOptions, hook, excludes) {
};
}
}
const EXCLUDE_HOOKS = ['onReady'];
const EXCLUDE_HOOKS = [ON_READY];
function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
hooks.forEach((hook) => initHook$1(mpOptions, hook, excludes));
}
......@@ -162,12 +198,12 @@ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
}
const HOOKS = [
'onShow',
'onHide',
'onError',
'onThemeChange',
'onPageNotFound',
'onUnhandledRejection',
ON_SHOW,
ON_HIDE,
ON_ERROR,
ON_THEME_CHANGE,
ON_PAGE_NOT_FOUND,
ON_UNHANDLE_REJECTION,
];
function parseApp(instance, parseAppOptions) {
const internalInstance = instance.$;
......@@ -186,7 +222,7 @@ function parseApp(instance, parseAppOptions) {
slots: [],
});
ctx.globalData = this.globalData;
instance.$callHook('onLaunch', options);
instance.$callHook(ON_LAUNCH, options);
},
};
const vueOptions = instance.$.type;
......@@ -207,26 +243,6 @@ function initCreateApp(parseAppOptions) {
};
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
function initBehavior(options) {
return Behavior(options);
}
......@@ -784,7 +800,7 @@ function parsePage(vueOptions, parseOptions) {
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
};
return this.$vm && this.$vm.$callHook('onLoad', query);
return this.$vm && this.$vm.$callHook(ON_LOAD, query);
};
initHooks(methods, PAGE_HOOKS);
initUnknownHooks(methods, vueOptions);
......@@ -824,7 +840,7 @@ function initHook(name, options) {
}
}
Page = function (options) {
initHook('onLoad', options);
initHook(ON_LOAD, options);
return MPPage(options);
};
Component = function (options) {
......@@ -864,7 +880,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
if (this.$vm) {
this.$vm.$callHook('mounted');
this.$vm.$callHook('onReady');
this.$vm.$callHook(ON_READY);
}
},
detached() {
......
......@@ -113,19 +113,55 @@ function initMocks(instance, mpInstance, mocks) {
});
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
const ON_HIDE = 'onHide';
//App
const ON_LAUNCH = 'onLaunch';
const ON_ERROR = 'onError';
const ON_THEME_CHANGE = 'onThemeChange';
const ON_PAGE_NOT_FOUND = 'onPageNotFound';
const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
//Page
const ON_LOAD = 'onLoad';
const ON_READY = 'onReady';
const ON_UNLOAD = 'onUnload';
const ON_RESIZE = 'onResize';
const ON_TAB_ITEM_TAP = 'onTabItemTap';
const ON_REACH_BOTTOM = 'onReachBottom';
const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
const PAGE_HOOKS = [
'onLoad',
'onShow',
// 'onReady', // lifetimes.ready
'onHide',
'onUnload',
'onResize',
// 'onPageScroll', // 影响性能,开发者手动注册
'onTabItemTap',
'onReachBottom',
'onPullDownRefresh',
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'onAddToFavorites',
ON_LOAD,
ON_SHOW,
ON_HIDE,
ON_UNLOAD,
ON_RESIZE,
ON_TAB_ITEM_TAP,
ON_REACH_BOTTOM,
ON_PULL_DOWN_REFRESH,
ON_ADD_TO_FAVORITES,
];
function findHooks(vueOptions, hooks = new Set()) {
if (vueOptions) {
......@@ -156,7 +192,7 @@ function initHook$1(mpOptions, hook, excludes) {
};
}
}
const EXCLUDE_HOOKS = ['onReady'];
const EXCLUDE_HOOKS = [ON_READY];
function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
hooks.forEach((hook) => initHook$1(mpOptions, hook, excludes));
}
......@@ -165,12 +201,12 @@ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
}
const HOOKS = [
'onShow',
'onHide',
'onError',
'onThemeChange',
'onPageNotFound',
'onUnhandledRejection',
ON_SHOW,
ON_HIDE,
ON_ERROR,
ON_THEME_CHANGE,
ON_PAGE_NOT_FOUND,
ON_UNHANDLE_REJECTION,
];
function parseApp(instance, parseAppOptions) {
const internalInstance = instance.$;
......@@ -189,7 +225,7 @@ function parseApp(instance, parseAppOptions) {
slots: [],
});
ctx.globalData = this.globalData;
instance.$callHook('onLaunch', options);
instance.$callHook(ON_LAUNCH, options);
},
};
const vueOptions = instance.$.type;
......@@ -210,26 +246,6 @@ function initCreateApp(parseAppOptions) {
};
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
function initBehavior(options) {
return Behavior(options);
}
......@@ -793,7 +809,7 @@ function parsePage(vueOptions, parseOptions) {
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
};
return this.$vm && this.$vm.$callHook('onLoad', query);
return this.$vm && this.$vm.$callHook(ON_LOAD, query);
};
initHooks(methods, PAGE_HOOKS);
initUnknownHooks(methods, vueOptions);
......@@ -833,7 +849,7 @@ function initHook(name, options) {
}
}
Page = function (options) {
initHook('onLoad', options);
initHook(ON_LOAD, options);
return MPPage(options);
};
Component = function (options) {
......@@ -1010,7 +1026,7 @@ function handleLink({ detail: { vuePid, nodeId, webviewId }, }) {
}
vm.$callSyncHook('created');
vm.$callHook('mounted');
vm.$callHook('onReady');
vm.$callHook(ON_READY);
}
function parse(componentOptions, { handleLink }) {
componentOptions.methods.__l = handleLink;
......@@ -1033,7 +1049,7 @@ function initLifetimes(lifetimesOptions) {
if (this.$vm && lifetimesOptions.isPage(this)) {
this.$vm.$callSyncHook('created');
this.$vm.$callHook('mounted');
this.$vm.$callHook('onReady');
this.$vm.$callHook(ON_READY);
}
else {
this.is && console.warn(this.is + ' is not ready');
......
此差异已折叠。
......@@ -113,19 +113,55 @@ function initMocks(instance, mpInstance, mocks) {
});
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
const ON_HIDE = 'onHide';
//App
const ON_LAUNCH = 'onLaunch';
const ON_ERROR = 'onError';
const ON_THEME_CHANGE = 'onThemeChange';
const ON_PAGE_NOT_FOUND = 'onPageNotFound';
const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
//Page
const ON_LOAD = 'onLoad';
const ON_READY = 'onReady';
const ON_UNLOAD = 'onUnload';
const ON_RESIZE = 'onResize';
const ON_TAB_ITEM_TAP = 'onTabItemTap';
const ON_REACH_BOTTOM = 'onReachBottom';
const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
const PAGE_HOOKS = [
'onLoad',
'onShow',
// 'onReady', // lifetimes.ready
'onHide',
'onUnload',
'onResize',
// 'onPageScroll', // 影响性能,开发者手动注册
'onTabItemTap',
'onReachBottom',
'onPullDownRefresh',
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'onAddToFavorites',
ON_LOAD,
ON_SHOW,
ON_HIDE,
ON_UNLOAD,
ON_RESIZE,
ON_TAB_ITEM_TAP,
ON_REACH_BOTTOM,
ON_PULL_DOWN_REFRESH,
ON_ADD_TO_FAVORITES,
];
function findHooks(vueOptions, hooks = new Set()) {
if (vueOptions) {
......@@ -153,7 +189,7 @@ function initHook$1(mpOptions, hook, excludes) {
};
}
}
const EXCLUDE_HOOKS = ['onReady'];
const EXCLUDE_HOOKS = [ON_READY];
function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
hooks.forEach((hook) => initHook$1(mpOptions, hook, excludes));
}
......@@ -162,12 +198,12 @@ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
}
const HOOKS = [
'onShow',
'onHide',
'onError',
'onThemeChange',
'onPageNotFound',
'onUnhandledRejection',
ON_SHOW,
ON_HIDE,
ON_ERROR,
ON_THEME_CHANGE,
ON_PAGE_NOT_FOUND,
ON_UNHANDLE_REJECTION,
];
function parseApp(instance, parseAppOptions) {
const internalInstance = instance.$;
......@@ -186,7 +222,7 @@ function parseApp(instance, parseAppOptions) {
slots: [],
});
ctx.globalData = this.globalData;
instance.$callHook('onLaunch', options);
instance.$callHook(ON_LAUNCH, options);
},
};
const vueOptions = instance.$.type;
......@@ -207,26 +243,6 @@ function initCreateApp(parseAppOptions) {
};
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
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}` : '';
}
function initBehavior(options) {
return Behavior(options);
}
......@@ -784,7 +800,7 @@ function parsePage(vueOptions, parseOptions) {
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
};
return this.$vm && this.$vm.$callHook('onLoad', query);
return this.$vm && this.$vm.$callHook(ON_LOAD, query);
};
initHooks(methods, PAGE_HOOKS);
initUnknownHooks(methods, vueOptions);
......@@ -824,7 +840,7 @@ function initHook(name, options) {
}
}
Page = function (options) {
initHook('onLoad', options);
initHook(ON_LOAD, options);
return MPPage(options);
};
Component = function (options) {
......@@ -864,7 +880,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
// https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
if (this.$vm) {
this.$vm.$callHook('mounted');
this.$vm.$callHook('onReady');
this.$vm.$callHook(ON_READY);
}
},
detached() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册