欢迎光临,了解微信小程序开发,就上易用通!

Charlotte微信小程序开发(三)--交互反馈

发布:2018-04-23 12:12浏览: 来源:网络 作者:cola

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);
});





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。