uniapp:负责打包app.
cocos creator:负责生成index.html文件
uniapp:
1.地址传参,用于用户识别
<web-view ref="webview" src="http://gm.a1.test.ifelman.com/?fullscreen=15&token=7bb16e81848e898dbb01201e6658b508" @message="getMessage"></web-view>
2.@message:用于游戏给uniapp传送函数
methods: {
getMessage(data){
}
}
$ref:用于uniapp给游戏转送函数
methods: {
getMessage(data){
this.$refs.webview.evalJs("kkk(123)");
}
}
cocos:
1.在index.html需要引入script
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
2.用于游戏给uniapp传送函数
if(window['uni'])
{
window['uni'].postMessage({
data: {
fun:'game_out'
}
});
}
3.用于uniapp给游戏转送函数
onLoad () {
window['kkk'] = ()=>{
console.log('cmd_test');
this.label.string = '123';
}
}
4.解析地址传参
ar reg = new RegExp("(^|&)" + 'token' + "=([^&]*)(&|$)" + "targetUserId" + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
var url = window.location.href;
let url_temp = url.split('?');
console.log('url_temp',url_temp)
let url_temp1 = url_temp[1].split('&');
console.log('url_temp1',url_temp1)
let token = url_temp1[1].split('=')[1];
网友评论