本文編輯: 揚瀏覽 6281
版權所有,嚴禁轉載
顯示模態彈窗
wx.showModal(OBJECT)
wxml
<view class="page">
<view class="page__hd">
<text class="page__title">modal</text>
<text class="page__desc">模式對話框</text>
</view>
<view class="page__bd">
<view class="btn-area">
<button type="default" bindtap="showModel1">簡單設定的modal</button>
<button type="default" bindtap="showModel2">全部自定義設定的modal2</button>
</view>
</view>
</view>
js
Page({
data: {
},
showModel1:function(){
wx.showModal({
title: '提示',
content: '這是一個簡單設置的彈窗',
success: function(res) {
if (res.confirm) {
console.log('用戶點擊確定')
}
}
})
},
showModel2:function(){
wx.showModal({
title: '提示',
content: '這是一個設定過全部屬性模態彈窗',
showCancel: true,
confirmText:'好的',
confirmColor:'#FF0000',
cancelText: '算了',
cancelColor:'#999999',
success: function(res) {
if (res.confirm) {
console.log('用戶點擊確定');
}else{
console.log('用戶點擊取消');
}
},
fail:function(){
console.log('接口調用失敗');
},
complete:function(){
console.log('接口調用結束')
}
})
},
})
wxss
.page {
min-height: 100%;
flex: 1;
background-color: #FBF9FE;
font-size: 32rpx;
font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
overflow: hidden;
}
.page__hd{
padding: 50rpx 50rpx 100rpx 50rpx;
text-align: center;
}
.page__title{
display: inline-block;
padding: 20rpx 40rpx;
font-size: 32rpx;
color: #AAAAAA;
border-bottom: 1px solid #CCCCCC;
}
.page__desc{
display: none;
margin-top: 20rpx;
font-size: 26rpx;
color: #BBBBBB;
}
.btn-area{
padding: 0 30px;
}
.btn-area button{
margin-top: 20rpx;
margin-bottom: 20rpx;
}
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
title | String | 是 | 提示的標題 |
content | String | 是 | 提示的內容 |
showCancel | Boolean | 否 | 是否顯示取消按鈕,默認為 true |
cancelText | String | 否 | 取消按鈕的文字,默認為”取消”,最多 4 個字符 |
cancelColor | HexColor | 否 | 取消按鈕的文字顏色,默認為”#000000” |
confirmText | String | 否 | 確定按鈕的文字,默認為”確定”,最多 4 個字符 |
confirmColor | HexColor | 否 | 確定按鈕的文字顏色,默認為”#3CC51F” |
success | Function | 否 | 接口調用成功的回調函數,返回res.confirm為true時,表示用戶點擊確定按鈕 |
fail | Function | 否 | 接口調用失敗的回調函數 |
complete | Function | 否 | 接口調用結束的回調函數(調用成功、失敗都會執行) |