uni-app封装组件实现下方滑动弹出模态框

子组件

javascript 复制代码
<template>
    <div class="bottom-modal" :class="{'show': showModal}">
      <div class="modal-content" :class="{'show': showModal}">
        <!-- 内容区域 -->
        <slot></slot>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    name: 'BottomModal',
    props: {
      showModal: {
        type: Boolean,
        default: false
      }
    },
    methods: {
    }
  }
  </script>
  
  <style lang="scss">
  .bottom-modal {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 0;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: hidden;
    transition: height 0.2s ease-out;
    z-index: 99;
  }
  
  .bottom-modal.show {
    height: 100%;
  }
  
  .modal-content {
    background-color: #fff;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    box-shadow: 0px -2px 10px rgba(0, 0, 0, 0.1);
    padding: 16px;

    // 内容显示在底部
    position: absolute;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
    z-index: 999;
    height: 0;
    transition: all 0.5s linear;
  }
  .modal-content.show {
    height: 60vh;
  }
  
  .modal-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
  </style>
  

父组件

javascript 复制代码
<script>
import BottomModal from "@/components/BottomModal.vue"

export default {
    components: {
        BottomModal
    },
    data() {
		return {
		    showModal: false
		}
	},
	methods: {
        radioChange(e) {
            console.log("radioChange", e.detail.value)
        }
	}
}
</script>
<template>
    <bottom-modal :showModal="showModal">
        <view class="my-modal">
            <text class="title">订单取消</text>
            <text>请选择取消订单的原因:</text>

            <radio-group @change="radioChange">
                <view>
                    <label class="item">
                        <text>商品无货</text>
                        <radio :value="1" style="transform: scale(0.6)" />
                    </label>
                </view>
                <view>
                    <label class="item">
                        <text>不想要了</text>
                        <radio :value="2" style="transform: scale(0.6)" />
                    </label>
                </view>
                <view>
                    <label class="item">
                        <text>商品信息填错了</text>
                        <radio :value="3" style="transform: scale(0.6)" />
                    </label>
                </view>
                <view>
                    <label class="item">
                        <text>地址信息填写错误</text>
                        <radio :value="4" style="transform: scale(0.6)" />
                    </label>
                </view>
                <view>
                    <label class="item">
                        <text>商品降价</text>
                        <radio :value="5" style="transform: scale(0.6)" />
                    </label>
                </view>
                <view>
                    <label class="item">
                        <text>其它</text>
                        <radio :value="6" style="transform: scale(0.6)" />
                    </label>
                </view>
            </radio-group>
            <view class="cancel-confirm">
                <text @click="handleCancel">取消</text>
                <text @click="handleConfirm" class="confirm">确认</text>
            </view>
        </view>
    </bottom-modal>
</template>

<style lang="scss">
.my-modal {
    display: flex;
    flex-direction: column;
    font-size: 26rpx;

    .item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 30rpx;
        padding-right: 30rpx;
    }
    .title {
        margin-top: 15rpx;
        font-size: 30rpx;
        text-align: center;
    }
    .cancel-confirm {
        display: flex;
        justify-content: space-around;
        margin-top: 30rpx;

        text {
            width: 300rpx;
            height: 60rpx;
            line-height: 60rpx;
            text-align: center;
            border: 1px solid #e6e2e2;
            border-radius: 30rpx;
        }
        .confirm {
            background-color: #27BA9B;
            border: none;
            color: #fff;
        }
    }
}
</style>

效果图

相关推荐
veneno14 小时前
大量异步并发请求控制并发解决方案
前端
i***t91915 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
oden15 小时前
2025博客框架选择指南:Hugo、Astro、Hexo该选哪个?
前端·html
小光学长15 小时前
基于ssm的宠物交易系统的设计与实现850mb48h(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·前端·数据库
云中飞鸿15 小时前
函数:委托
javascript
小小前端要继续努力15 小时前
渐进增强、优雅降级及现代Web开发技术详解
前端
老前端的功夫16 小时前
前端技术选型的理性之道:构建可量化的ROI评估模型
前端·javascript·人工智能·ubuntu·前端框架
狮子座的男孩16 小时前
js函数高级:04、详解执行上下文与执行上下文栈(变量提升与函数提升、执行上下文、执行上下文栈)及相关面试题
前端·javascript·经验分享·变量提升与函数提升·执行上下文·执行上下文栈·相关面试题
爱学习的程序媛17 小时前
《JavaScript权威指南》核心知识点梳理
开发语言·前端·javascript·ecmascript
乐观主义现代人17 小时前
go 面试
java·前端·javascript