[add] EventBus使用 雙向溝通
This commit is contained in:
@@ -21,21 +21,28 @@ export default class HelloWorld extends cc.Component {
|
||||
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
|
||||
// protected onLoad() {}
|
||||
protected onLoad() {
|
||||
let self = this;
|
||||
this.Label.string = this.Text;
|
||||
window["eventBus"].on('SendContent', (content: string) => {
|
||||
self.Label.string = content;
|
||||
})
|
||||
}
|
||||
|
||||
public onClickBtn() {
|
||||
let url: string = window.location.search;
|
||||
let URLscheme: any[] = [];
|
||||
if (url.indexOf("?") !== -1) {
|
||||
let str = url.substring(1);
|
||||
let strs = str.split("&");
|
||||
for (let i = 0; i < strs.length; i++) {
|
||||
URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
|
||||
}
|
||||
}
|
||||
if (URLscheme["host"]) {
|
||||
opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]);
|
||||
window.close();
|
||||
}
|
||||
window["eventBus"].emit("Alert", "hello");
|
||||
// let url: string = window.location.search;
|
||||
// let URLscheme: any[] = [];
|
||||
// if (url.indexOf("?") !== -1) {
|
||||
// let str = url.substring(1);
|
||||
// let strs = str.split("&");
|
||||
// for (let i = 0; i < strs.length; i++) {
|
||||
// URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
|
||||
// }
|
||||
// }
|
||||
// if (URLscheme["host"]) {
|
||||
// opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]);
|
||||
// window.close();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
103781
Project/build-templates/web-mobile/cocos2d-js.js
Normal file
103781
Project/build-templates/web-mobile/cocos2d-js.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user