|
1.wx.showToast(OBJECT) 顯示消息提示框
//封裝在app.js中
showToast:function(msg){
wx.showToast({
title: msg.title,
icon: msg.icon,
duration: 2000
})
}
//在其他頁(yè)面調(diào)用
let app=getApp();
let loading={
title:'加載中',
icon:'loading'
}
let success={
title:'創(chuàng)建成功',
icon:'success'
}
app.showToast(loading);
app.showToast(success);
2.wx.showModal(OBJECT) 顯示模態(tài)彈窗
//封裝在app.js中,異步操作需要寫(xiě)成promise來(lái)接收參數(shù)
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('用戶點(diǎn)擊確定')
} else if (res.cancel) {
resolve(res.cancel);
//console.log('用戶點(diǎn)擊取消')
}
}
})
})
}
//在其他頁(yè)面調(diào)用
let app=getApp();
let modal={
title:'提示',
content:'用戶名不能為空'
}
app.showModal(modal).then((data)=>{
console.log('用戶點(diǎn)擊了:',data);
});
|