Dialog对话框
引入
在app.json或index.json中引入组件,默认为ES6版本
"usingComponents": {
"vtu-dialog": "/miniprogram_npm/vtuweapp/dialog/vtu-dialog"
}
代码演示
普通对话框
<vtu-btn bind:click="alert1" type="primary" custom-class="dialog-btn">普通对话框</vtu-btn>
<vtu-btn bind:click="alert2" type="primary" custom-class="dialog-btn">普通对话框(无取消按钮)</vtu-btn>
<vtu-btn bind:click="alert3" type="danger" custom-class="dialog-btn">确认对话框(开放能力)</vtu-btn>
<vtu-btn bind:click="alert4" type="success" custom-class="dialog-btn">自定义按钮排列</vtu-btn>
<vtu-btn bind:click="alert5" type="warning" custom-class="dialog-btn">点击遮罩关闭</vtu-btn>
<vtu-btn bind:click="alert6" type="success" custom-class="dialog-btn">横向排列</vtu-btn>
<vtu-dialog id="Vtu-Dialog"></vtu-dialog>
import Dialog from "../../../miniprogram_npm/vtuweapp/dialog/vtu-index";
Page({
data: {},
alert1: function() {
Dialog().alert({
title: '普通提示',
content: '显示您要确定的内容信息'
})
},
alert2: function() {
Dialog().alert({
title: '普通提示',
content: '显示您要确定的内容信息',
showCancel: false
})
},
alert3: function() {
Dialog().confirm({
title: '确认对话框',
content: '系统需要您的授权,请登录',
confirmLabel: '登录',
confirmOpenType: 'getUserInfo',
cancelLabel: '不需要',
success: function(e) {
wx.showToast({
title: "已确认",
icon: 'none',
duration: 2000
});
},
fail: function() {
wx.showToast({
title: "已取消",
icon: 'none',
duration: 2000
});
}
})
},
alert4: function() {
Dialog().open({
title: '自定义对话框',
content: '请选择付款方式',
buttons: [
{
type: 'primary',
label: '微信支付(异步)',
async: true,
click: function(e) {
setTimeout(function() {
Dialog().close()
}, 2000)
}
},
{
type: 'danger',
label: '支付宝支付',
click: function(e) {
}
},
{
type: 'default',
label: '取消',
click: function(e) {
Dialog().close()
}
}
]
})
},
alert5: function() {
Dialog().confirm({
title: '确认对话框',
content: '系统需要您的授权,请登录',
confirmLabel: '登录',
confirmAsync: true,
confirmOpenType: 'getUserInfo',
cancelLabel: '不需要',
closeOnClickOverlay: true,
success: function(e) {
setTimeout(function() {
Dialog().close()
}, 2000)
},
fail: function() {
wx.showToast({
title: "已取消",
icon: 'none',
duration: 2000
});
}
})
},
alert6: function() {
Dialog().open({
title: '自定义对话框',
content: '请选择付款方式',
verticalButtons: false,
buttons: [
{
type: 'primary',
label: '微信支付',
icon: "iconfont icon-share",
click: function(e) {
setTimeout(function() {
Dialog().close()
}, 2000)
}
},
{
type: 'danger',
label: '支付宝支付',
click: function(e) {
}
},
{
type: 'default',
label: '取消',
click: function(e) {
Dialog().close()
}
}
]
})
},
closeCustomDialog: function() {
Dialog("Vtu-Custom-Dialog").close()
}
});
自定义对话框
<vtu-btn bind:click="alert7" type="primary" custom-class="dialog-btn">自定义对话框</vtu-btn>
<vtu-dialog id="Vtu-Custom-Dialog" show="{{show}}" title="自定义对话框内容" user-content-slot>
<view class="Vtu-Custom-Center">
<vtu-radio-group model="1" align="right">
<vtu-radio value="1" label="北京" icon="iconfont icon-biaoxing" ></vtu-radio>
<vtu-radio value="2" label="上海" icon="iconfont icon-xihuan" ></vtu-radio>
<vtu-radio value="3" label="深圳" icon="iconfont icon-sousuo"></vtu-radio>
<vtu-radio value="4" label="南京" icon="iconfont icon-shangchuan"></vtu-radio>
</vtu-radio-group>
</view>
<view class="Vtu-Custom-Btn">
<vtu-btn type="primary" inlineBlock custom-class="dialog-custom-btn">确定</vtu-btn>
<vtu-btn bind:click="closeCustomDialog" inlineBlock custom-class="dialog-custom-btn">取消</vtu-btn>
</view>
</vtu-dialog>
import Dialog from "../../../miniprogram_npm/vtuweapp/dialog/vtu-index";
Page({
data: {
show: false
},
alert7: function() {
this.setData({
show: true
})
},
closeCustomDialog: function() {
Dialog("Vtu-Custom-Dialog").close()
}
});
组件参数