Ai
1 Star 2 Fork 1

旻天信息/mttk-vue-wrap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
compBaseLifecycle.ts 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
旻天信息 提交于 2024-05-14 09:26 +08:00 . Update license
import {
onMounted,
onUpdated,
onUnmounted,
onBeforeMount,
onBeforeUpdate,
onBeforeUnmount,
onErrorCaptured,
onActivated,
onDeactivated,
} from "vue";
export function buildLifeCycle(contextWrap,configStd){
//
function registerLifeCycles() {
onMounted(() => invokeLifecycle("onMounted"));
onUpdated(() => invokeLifecycle("onUpdated"));
onUnmounted(() => invokeLifecycle("onUnmounted"));
onBeforeMount(() => invokeLifecycle("onBeforeMount"));
onBeforeUpdate(() => invokeLifecycle("onBeforeUpdate"));
onBeforeUnmount(() => invokeLifecycle("onBeforeUnmount"));
onActivated(() => invokeLifecycle("onActivated"));
onDeactivated(() => invokeLifecycle("onDeactivated"));
onErrorCaptured((err, instance, info) =>
invokeLifecycle("onErrorCaptured", err, instance, info)
);
}
//lifecycle
function invokeLifecycle(type: string, ...args) {
// console.log('**************'+type,contextWrap)
const handler = configStd.value["^" + type];
if (!handler) {
return;
}
if (Array.isArray(handler)) {
for (const single of handler) {
if (typeof single == "function") {
single(contextWrap, ...args);
} else {
throw Error("Unsuported handler for lifecycle:" + type + " in array");
}
}
} else if (typeof handler == "function") {
handler(contextWrap, ...args);
} else {
throw Error("Unsuported handler for lifecycle:" + type);
}
}
//
return registerLifeCycles
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/jamie0828/mttk-vue-wrap.git
git@gitee.com:jamie0828/mttk-vue-wrap.git
jamie0828
mttk-vue-wrap
mttk-vue-wrap
master

搜索帮助