1.wx.showToast(OBJECT) 显示消息提示框 //封装在app.js中 showToast:function(msg){ wx.showToast({ title: msg.title, icon: msg.icon, duration: 2000 }) } //在其他页面调用 let app=getApp(); let loading={ title:'加载中', icon:'loading' } let success={ title:'创建成功', icon:'success' } app.showToast(loading); app.showToast(success); 2.wx.showModal(OBJECT) 显示模态弹窗 //封装在app.js中,异步操作需要写成promise来接收参数 showModal:function(msg){ return new Promise((resolve,reject)=>{ wx.showModal({ title: msg.title', content: msg.content, success: function(res) { if (res.confirm) { resolve(res.confirm); //console.log('用户点击确定') } else if (res.cancel) { resolve(res.cancel); //console.log('用户点击取消') } } }) }) } //在其他页面调用 let app=getApp(); let modal={ title:'提示', content:'用户名不能为空' } app.showModal(modal).then((data)=>{ console.log('用户点击了:',data); }); |