uniapp使用webview嵌入h5,并在h5中触发uniapp推送系统通知
uniapp使用webview嵌入h5
嵌入h5如下
<web-view src="http://xxx.xxx.xxx.xxx:8000" @message="handleMessage"></web-view>
通过@message创建一个handleMessage事件。
handleMessage(evt) {
console.log('原始信息:' + evt)
console.log('接收到的消息:' + JSON.stringify(evt));
if (evt) {
// let data={};
let data = JSON.parse(evt.detail.data);
console.log('json解析:' + JSON.stringify(data));
if (data && data.content && data.title && data.content != '' && data.title != '') {
uni.createPushMessage({
content: data.content, // 推送内容
title: data.title, // 推送标题
sound: "system",
success: function(res) {
console.log('推送成功', res);
},
fail: function(err) {
console.log