1,首先可以简单的看一下HTML5+ API文档了解一下对应的方法
HTML5+API:https://www.html5plus.org/doc/zh_cn/push.html#plus.push.MessageOptions
2,先在manifest.json勾选一下Push推送
3, 需要配置一下并传给后端
4,可以在api.js里面做为公用参数把clientid传给后端
//#ifdef APP-PLUSlet REGISTER_ID = plus.push.getClientInfo()//#endifdata.REGISTER_ID = REGISTER_ID.clientid
5,功能实现,写在APP.vue中。可以看到前面二行代码我做了一下测试,本地创建消息测试成功。
onLaunch: function() {//消息推送功能// #ifdef APP-PLUSlet options={cover:false,title:'测试'}plus.push.createMessage('你好你好你好你好你好你好你好你好',"",options)let tm=false;// //点击消息plus.push.addEventListener('click',(msg)=>{console.log(msg,'点击消息');clearTimeout(tm)tm = setTimeout(()=>{uni.navigateTo({url:msg.payload.page})},1500)},false)//监听消息plus.push.addEventListener('receive',(msg)=>{clearTimeout(tm)plus.nativeUI.toast( msg.payload.content );},false)// #endif}