test: 应用通信添加基座 adapter 信息
This commit is contained in:
@@ -3,6 +3,8 @@ import { onBeforeUnmount, onMounted } from 'vue';
|
||||
|
||||
import WujieVue from 'wujie-vue3';
|
||||
|
||||
import { version } from '/package.json';
|
||||
|
||||
const props = defineProps<{
|
||||
[key: string]: any;
|
||||
accessToken?: string;
|
||||
@@ -33,16 +35,47 @@ const handleMessage = (data: any) => {
|
||||
console.log('收到子应用消息:', data);
|
||||
};
|
||||
|
||||
// 准备传递给子应用的数据
|
||||
const subAppProps = {
|
||||
...props,
|
||||
adapterInfo: {
|
||||
version,
|
||||
},
|
||||
};
|
||||
|
||||
// 监听子应用的事件
|
||||
const handleReady = (data: any) => {
|
||||
console.log('子应用就绪:', data);
|
||||
// 可以在这里执行一些操作
|
||||
};
|
||||
|
||||
const handleRenderSuccess = () => {
|
||||
console.log('子应用渲染成功');
|
||||
// 通知父应用
|
||||
};
|
||||
|
||||
const handleRenderFail = (error: any) => {
|
||||
console.error('子应用渲染失败:', error);
|
||||
// 处理错误情况
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
// 注册事件监听
|
||||
bus.$on('message', handleMessage);
|
||||
bus.$on('ready', handleReady);
|
||||
bus.$on('render-success', handleRenderSuccess);
|
||||
bus.$on('render-fail', handleRenderFail);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// 移除所有事件监听
|
||||
bus.$off('message', handleMessage);
|
||||
bus.$off('ready', handleReady);
|
||||
bus.$off('render-success', handleRenderSuccess);
|
||||
bus.$off('render-fail', handleRenderFail);
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
{{ 1 }}
|
||||
<div style="width: 100%; height: 100%">
|
||||
<WujieVue
|
||||
:id="name"
|
||||
@@ -53,7 +86,7 @@ onBeforeUnmount(() => {
|
||||
:degrade="degrade"
|
||||
width="100%"
|
||||
height="100%"
|
||||
:props="props"
|
||||
:props="subAppProps"
|
||||
:before-load="beforeLoad"
|
||||
:after-mount="afterMount"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user