微信小程序消息提醒封装

1.在app.js中获取当前页面对象,进行函数绑定

initNotice(){

let pages = getCurrentPages(); // 获取页面栈

let page = pages[pages.length-1];// 获取当前页面对象

page.showCustomToast = function(e){ // 绑定事件到当前对象

wx.showToast({

title: e,

duration:1000,

icon:\'none\'

})

}

page.showCustomModal = function(title,callback){// 绑定事件到当前对象,至于左右按钮的样式和取消按钮的事件,根据自己的业务自己添加

wx.showModal({

title: \'\',

content: title,

success(res) {

if (res.confirm) {

callback();

}

}

})

}

},

2. 页面初始化

onLoad: function () { // 页面初始化 options为页面跳转所带来的参数

let app = getApp();//获取全局app对象

app.initNotice(); // 调用这个函数进行事件的初始化绑定

},

3 调用

onShow: function () {

let that = this;

that.showCustomModal(\'测试一下Modal\',function(){

that.showCustomToast("测试成功!");

});

},