当前位置:网站首页>(forward) usage of PostMessage
(forward) usage of PostMessage
2022-07-24 20:08:00 【CaseyWei】
1、 The parent page sends messages to the child page
let data = {type: 'answerResult', data: jsonData.data};
this.$refs.iframe.contentWindow.postMessage(data, '*');
2、 The child page sends a message to the parent page
let parentData = {type: 'passDataBack', data: passData};
window.parent.postMessage(parentData, '*');
3、 Method of receiving message
window.addEventListener('message', function (e) {})
encapsulation
// Parent page
mounted(){
window.addEventListener("message", this.handleMessage)
},
methods:{
/**
* towards iframe How to transfer values
* @param {Object} data
*/
sendMessage(data){
const iframe = this.$refs.iframePage.contentWindow;
iframe.postMessage(data, '*');
},
/**
* The method of listening to the value passed from the sub page
* @param {Object} event
*/
handleMessage (event) {
// dosomething
}
}
// Subpage
mounted(){
window.addEventListener("message", this.handleMessage)
},
methods:{
/**
* The method of passing values to the parent page
* @param {Object} data
*/
sendMessage(data){
window.parent.postMessage(data, '*');
}
/**
* The method of listening to the value passed from the parent page
* @param {Object} event
*/
handleMessage (event) {
// dosomething
}
}
link :https://www.jianshu.com/p/ae840f7d7f8b
边栏推荐
- Unity3d eventsystem (event)
- Xiaomi 12s ultra products are so powerful, but foreigners can't buy Lei Jun: first concentrate on the Chinese market
- Work notes - some problems encountered when using jest
- 02 | environment preparation: how to install and configure a basic PHP development environment under windows?
- Common methods of string class
- Valdo2021 - vascular space segmentation in vascular disease detection challenge (3)
- 872. Maximum common divisor
- Anaconda installs labelimg (super simple and available)
- Redis common configuration description
- Sword finger offer 52. The first common node of the two linked lists
猜你喜欢

Login Huawei device in SSH mode

C# 窗体应用TreeView控件使用

Stop using UUID indiscriminately. Have you tested the performance gap between self incrementing ID and UUID?

Todolist case

C form application treeview control use

Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr
Cmake series tutorial 2 HelloWorld

Connect the smart WiFi remote control in the home assistant
![Microservice architecture | service monitoring and isolation - [sentinel] TBC](/img/28/8ca90e9dbd492688e50446f55959ff.png)
Microservice architecture | service monitoring and isolation - [sentinel] TBC

Machine learning job interview summary: five key points that resume should pay attention to
随机推荐
Data transmission of different fragments in the same activity
YouTube "label products" pilot project launched
Duilib actual combat 1- imitate Baidu online disk login interface
【德味】安全:如何为行人提供更多保护
872. Maximum common divisor
Sql164 next day retention rate of new users per day in November 2021
Monotone stack and monotone queue (linear complexity optimization)
Write a batch and start redis
PD user manual
Wechat stores build order pages and automatically grab tickets
存储类别
BGP - border gateway protocol
Thymeleaf application notes
Leetcode 48 rotating image (horizontal + main diagonal), leetcode 221 maximum square (dynamic programming DP indicates the answer value with ij as the lower right corner), leetcode 240 searching two-d
What is IDE (integrated development environment)
02 | 环境准备:如何在windows下安装和配置一个基本的php开发环境?
Substr and substring function usage in SQL
strlen函数剖析和模拟实现
Hcip early summary
Risk control system, implemented by flink+clickhouse!