GameTalk.vue
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!-- 说说 -->
<template>
<iframe id="iframe_chat" ref="iframe1" :src="src + yiqiu_id" @load="iframeLoaded" loading="lazy" width="100%" frameborder="0" allowfullscreen></iframe>
</template>
<script lang="ts">
export default ({
name: 'GameTalk',
props: {
yiqiu_id: {
type: Number,
required: true
}
},
mounted (): any {
var topMain = document.getElementById('topMain');
if (topMain) {
(document.getElementById("iframe_chat") as any).style.height = `calc(100vh - ${topMain.offsetHeight + 58}px)`;
}
},
data (): any {
return {
src: `/forum/zq_chat?matchid=`
};
},
methods: {
iframeLoaded () {
window.addEventListener('message', this.handleMessage, false);
},
handleMessage (event: any) {
console.info(event.data);
// // 注意:出于安全考虑,应该验证发送者
// if (event.origin !== 'https://example.com') return; // 确保消息来自正确的来源
// if (event.data.event === 'buttonClicked') {
// // 处理按钮点击事件
// console.log('Button clicked in the iframe:', event.data.data);
// }
},
}
});
</script>