Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【fix】页面生命周期onLoad和onShow的执行顺序问题。 #291

Closed
wants to merge 1 commit into from

Conversation

hycg
Copy link

@hycg hycg commented Jun 28, 2021

@SilurianYang 不知道作者大佬有没有更好的处理方法

@SilurianYang
Copy link
Owner

sort 介绍

  1. sort() 方法用原地算法对数组的元素进行排序,并返回数组。默认排序顺序是在将元素转换为字符串,然后比较它们的UTF-16代码单元值序列时构建的,由于它取决于具体实现,因此无法保证排序的时间和空间复杂性。
  2. 如果没有指明参数,那么元素会按照转换为的字符串的诸个字符的Unicode位点进行排序。例如 "Banana" 会被排列到 "cherry" 之前。当数字按由小到大排序时,9 出现在 80 之前,但因为(没有指明 参数),比较的数字会先被转换为字符串,所以在Unicode顺序上 "80" 要比 "9" 要靠前。

使用默认的 sort 无法满足我们的需求,最简单的是使用下面的这个方法,自主排序下就好了。

export const proxyVueSortHookName:{
app:Array<appVueSortHookRule>,
page:Array<pageVueSortHookRule>,
component:Array<comVueSortHookRule>
} = {
app: ['created', 'beforeMount', 'mounted', 'onLaunch', 'onShow', 'onHide', 'beforeDestroy', 'destroyed'],
page: ['created', 'beforeMount', 'mounted', 'onLoad', 'onReady', 'onShow', 'onResize', 'onHide', 'beforeDestroy', 'destroyed', 'onUnload'],
component: ['created', 'beforeMount', 'mounted', 'beforeDestroy', 'destroyed']
}

export function callHook(
key:pageTypeRule,
value:objectAny,
enterPath:string
):Array<Function> {
const resetHookFun:Array<Function> = [];
// Fixe: https://github.com/SilurianYang/uni-simple-router/issues/206
// Fixe: https://github.com/SilurianYang/uni-simple-router/issues/224
const hookList = proxyVueSortHookName[key];
for (let i = 0; i < hookList.length; i++) {
const [origin] = value[hookList[i]];
if (origin && origin.hook) {
resetHookFun.push(origin.hook(enterPath))
}
}
return resetHookFun;
}

@hycg
Copy link
Author

hycg commented Jun 29, 2021

完美,感谢大佬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants