Vue自定義模態對話框彈窗
本文實例為大傢分享瞭Vue自定義模態對話框彈窗的具體代碼,供大傢參考,具體內容如下
模態對話框彈窗效果:
父組件(應用頁面)主要代碼:
<template> <view class="app-container"> <modal-dialog showText="確定要取消收藏嗎?" :isShowDialog="isDialog" @cancel="isDialog = false" @confirm="confirmDelete"></modal-dialog> </view> </template> <script> import modalDialog from '@/components/modalDialog.vue'; export default { components:{ modalDialog }, data() { return { isDialog: false, } }, methods: { // 業務代碼...... this.isDialog = false; } } </script>
子組件(自定義組件)代碼:
<template> <view> <view class="global-mask" v-show="isShowDialog"></view> <view class="global-dialog" v-show="isShowDialog" style="top: 45%;"> <view class="title">溫馨提示</view> <view class="content"> <view class="text">{{showText}}</view> </view> <view class="btn"> <view class="left" @tap="cancel" v-if="isShowCancel">{{cancelText}}</view> <view class="right" @tap="confirm" v-if="isShowConfirm">{{confirmText}}</view> </view> </view> </view> </template> <script> export default { name: 'modalDialog', props: { showText: { type: String, default: '提示內容' }, isShowDialog: { type: Boolean, default: false }, isShowCancel: { type: Boolean, default: true }, cancelText: { type: String, default: '取消' }, isShowConfirm: { type: Boolean, default: true }, confirmText: { type: String, default: '確定' } }, data() { return { }; }, methods: { cancel() { this.$emit('cancel'); }, confirm() { this.$emit('confirm'); } } } </script> <style lang="scss"> .global-mask { position: fixed; top: 0; left: 0; z-index: 998; width: 100%; height: 100%; background: rgba($color: #000000, $alpha: 0.3); } .global-dialog { position: fixed; top: 500rpx; left: 60rpx; top: 45%; z-index: 999; width: 630rpx; background: #FFFFFF; border-radius: 15rpx; overflow: hidden; .title { font-size: 36rpx; font-weight: 500; text-align: center; line-height: 100rpx; padding-bottom: 10rpx; } .content { .text { font-size: 32rpx; text-align: center; padding-bottom: 40rpx; } .form { padding: 0 40rpx; .item { display: flex; align-items: center; justify-content: space-between; margin-bottom: 40rpx; input { width: 340rpx; height: 60rpx; border: 1px solid #eaeaea; border-radius: 10rpx; padding: 0 20rpx; } } } } .btn { border-top: 1px solid #eaeaea; display: flex; &> view { flex: 1; text-align: center; line-height: 100rpx; font-size: 32rpx; &.left { color: #666666; } &.right { color: #FFFFFF; background: #FF3F42; } } } } </style>
以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。