Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
92be62f5
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92be62f5
编写于
11月 19, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(h5): onLoad
上级
75d07614
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
46 addition
and
47 deletion
+46
-47
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+5
-4
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+14
-6
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+15
-7
packages/uni-h5/src/framework/setup/index.ts
packages/uni-h5/src/framework/setup/index.ts
+6
-25
packages/uni-vue/src/componentOptions/hooks.ts
packages/uni-vue/src/componentOptions/hooks.ts
+6
-5
未找到文件。
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
92be62f5
...
...
@@ -10039,16 +10039,17 @@ var serviceContext = (function (vue) {
}
});
if (mpType === 'page') {
instance.__isVisible = true;
try {
invokeHook(publicThis, ON_LOAD, instance.attrs.__pageQuery);
vue.nextTick(() => {
// 延迟onShow,保证组件的onShow也可以监听到
invokeHook(publicThis, ON_SHOW);
});
}
catch (e) {
console.error(e.message + LINEFEED + e.stack);
}
vue.nextTick(() => {
// 延迟onShow,保证组件的onShow也可以监听到
invokeHook(publicThis, ON_SHOW);
});
}
}
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
92be62f5
...
...
@@ -6525,7 +6525,7 @@ function injectLifecycleHook(name, hook, publicThis, instance) {
}
}
function
initHooks
(
options
,
instance
,
publicThis
)
{
options
.
mpType
||
publicThis
.
$mpType
;
const
mpType
=
options
.
mpType
||
publicThis
.
$mpType
;
Object
.
keys
(
options
).
forEach
((
name
)
=>
{
if
(
name
.
indexOf
(
"
on
"
)
===
0
)
{
const
hooks
=
options
[
name
];
...
...
@@ -6536,6 +6536,17 @@ function initHooks(options, instance, publicThis) {
}
}
});
if
(
mpType
===
"
page
"
)
{
instance
.
__isVisible
=
true
;
try
{
invokeHook
(
publicThis
,
uniShared
.
ON_LOAD
,
instance
.
attrs
.
__pageQuery
);
}
catch
(
e2
)
{
console
.
error
(
e2
.
message
+
uniShared
.
LINEFEED
+
e2
.
stack
);
}
vue
.
nextTick
(()
=>
{
invokeHook
(
publicThis
,
uniShared
.
ON_SHOW
);
});
}
}
function
applyOptions
(
options
,
instance
,
publicThis
)
{
initHooks
(
options
,
instance
,
publicThis
);
...
...
@@ -6919,12 +6930,9 @@ function setupPage(comp) {
setup
(
instance
)
{
instance
.
root
=
instance
;
const
route
=
usePageRoute
();
instance
.
attrs
.
__pageQuery
=
uniShared
.
decodedQuery
(
route
.
query
);
{
vue
.
nextTick
(()
=>
{
const
{
onLoad
}
=
instance
;
onLoad
&&
shared
.
invokeArrayFns
(
onLoad
,
uniShared
.
decodedQuery
(
route
.
query
));
});
return
route
.
query
;
return
instance
.
attrs
.
__pageQuery
;
}
}
});
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
92be62f5
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { I18N_JSON_DELIMITERS, once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { I18N_JSON_DELIMITERS, once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce,
ON_LOAD,
UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
let i18n;
...
...
@@ -13399,7 +13399,7 @@ function injectLifecycleHook(name, hook, publicThis, instance2) {
}
}
function initHooks(options, instance2, publicThis) {
options.mpType || publicThis.$mpType;
const mpType =
options.mpType || publicThis.$mpType;
Object.keys(options).forEach((name) => {
if (name.indexOf("on") === 0) {
const hooks = options[name];
...
...
@@ -13410,6 +13410,17 @@ function initHooks(options, instance2, publicThis) {
}
}
});
if (mpType === "page") {
instance2.__isVisible = true;
try {
invokeHook(publicThis, ON_LOAD, instance2.attrs.__pageQuery);
} catch (e2) {
console.error(e2.message + LINEFEED + e2.stack);
}
nextTick(() => {
invokeHook(publicThis, ON_SHOW);
});
}
}
function applyOptions(options, instance2, publicThis) {
initHooks(options, instance2, publicThis);
...
...
@@ -13963,13 +13974,10 @@ function setupPage(comp) {
setup(instance2) {
instance2.root = instance2;
const route = usePageRoute();
instance2.attrs.__pageQuery = decodedQuery(route.query);
const pageMeta = usePageMeta();
on
Mounted
(() => {
on
BeforeMount
(() => {
onPageShow(instance2, pageMeta);
const { onLoad, onShow } = instance2;
onLoad && invokeArrayFns$1(onLoad, decodedQuery(route.query));
instance2.__isVisible = true;
onShow && invokeArrayFns$1(onShow);
});
onMounted(() => {
onPageReady(instance2);
...
...
packages/uni-h5/src/framework/setup/index.ts
浏览文件 @
92be62f5
...
...
@@ -33,17 +33,13 @@ import { initLaunchOptions, getEnterOptions } from './utils'
interface
SetupComponentOptions
{
init
:
(
vm
:
ComponentPublicInstance
)
=>
void
setup
:
(
instance
:
ComponentInternalInstance
)
=>
Record
<
string
,
unknown
>
|
void
afterSetup
?:
(
instance
:
ComponentInternalInstance
,
query
:
Record
<
string
,
unknown
>
)
=>
void
setup
:
(
instance
:
ComponentInternalInstance
)
=>
Record
<
string
,
any
>
|
void
before
?:
(
comp
:
DefineComponent
)
=>
void
}
function
wrapperComponentSetup
(
comp
:
DefineComponent
,
{
init
,
setup
,
before
,
afterSetup
}:
SetupComponentOptions
{
init
,
setup
,
before
}:
SetupComponentOptions
)
{
before
&&
before
(
comp
)
const
oldSetup
=
comp
.
setup
...
...
@@ -54,9 +50,6 @@ function wrapperComponentSetup(
if
(
oldSetup
)
{
return
oldSetup
(
query
||
props
,
ctx
)
}
if
(
afterSetup
)
{
afterSetup
(
instance
,
query
!
)
}
}
}
...
...
@@ -85,29 +78,17 @@ export function setupWindow(comp: any, id: number) {
export
function
setupPage
(
comp
:
any
)
{
return
setupComponent
(
comp
,
{
init
:
initPage
,
afterSetup
(
instance
,
query
)
{
// 因为 onLoad 是在 setup 执行过程中添加的,故需要放在 after 中执行
const
{
onLoad
}
=
instance
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
query
))
},
setup
(
instance
)
{
instance
.
root
=
instance
// 组件 root 指向页面
const
route
=
usePageRoute
()
// node环境仅触发Page onLoad生命周期
// 存储参数,让 initHooks 中执行 onLoad 时,可以访问到
instance
.
attrs
.
__pageQuery
=
decodedQuery
(
route
.
query
)
if
(
__NODE_JS__
)
{
nextTick
(()
=>
{
const
{
onLoad
}
=
instance
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
})
return
route
.
query
return
instance
.
attrs
.
__pageQuery
as
Record
<
string
,
unknown
>
}
const
pageMeta
=
usePageMeta
()
onMounted
(()
=>
{
// 放在 onMounted 中,可以保证子组件中监听的相关生命周期也可以触发,比如onShow,onPageScroll
onBeforeMount
(()
=>
{
onPageShow
(
instance
,
pageMeta
)
const
{
onShow
}
=
instance
instance
.
__isVisible
=
true
onShow
&&
invokeArrayFns
(
onShow
)
})
onMounted
(()
=>
{
onPageReady
(
instance
)
...
...
packages/uni-vue/src/componentOptions/hooks.ts
浏览文件 @
92be62f5
...
...
@@ -41,15 +41,16 @@ export function initHooks(
}
}
})
if
(
__PLATFORM__
===
'
app
'
&&
mpType
===
'
page
'
)
{
if
((
__PLATFORM__
===
'
app
'
||
__PLATFORM__
===
'
h5
'
)
&&
mpType
===
'
page
'
)
{
instance
.
__isVisible
=
true
try
{
invokeHook
(
publicThis
,
ON_LOAD
,
instance
.
attrs
.
__pageQuery
)
nextTick
(()
=>
{
// 延迟onShow,保证组件的onShow也可以监听到
invokeHook
(
publicThis
,
ON_SHOW
)
})
}
catch
(
e
:
any
)
{
console
.
error
(
e
.
message
+
LINEFEED
+
e
.
stack
)
}
nextTick
(()
=>
{
// 延迟onShow,保证组件的onShow也可以监听到
invokeHook
(
publicThis
,
ON_SHOW
)
})
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录