model彈框:在屏幕中間彈出,讓你進行選擇:
效果:
代碼:
<button type="primary" bindtap="btnclick">按鈕</button> <modal title="標題" confirm-text="確認" cancel-text="取消" hidden="onOff" bindconfirm="modalConfirm" bindcancel="modalCancel"> 這里是會話內容 </modal>
page.js:
//獲取應用實例 const app = getApp() Page({ data: { onOff:true }, btnclick:function(){ var onOff = this.data.onOff; this.setData({onOff:!onOff}); } })
還可以使用JS:
btnclick:function(){ wx.showModal({ title: '提示', content: '這是一個模態彈窗', success: function(res) { if (res.confirm) { console.log('用戶點擊確定') } else if (res.cancel) { console.log('用戶點擊取消') } } }) }
具體的參數:
title:提示的標題;
content:提示的內容;
showCancel :是否顯示取消按鈕,默認是 false
canceText:取消按鈕的文字,默認是 “取消”
canceColor:取消按鈕的文字顏色,默認是 #000
confirmText:確定按鈕的文字。默認是 確定
confirmColor:確定按鈕的文字顏色。默認是 “#3CC5IF”
success:接口調用成功的回調函數。返回 res.confirm ==1時,表示用戶點擊。
fail:接口調用失敗的回調函數。
complete:接口調用結束的回調函數(調用成功或者失敗都會執行)