uniapp实战 —— 弹出层 uni-popup (含vue3子组件调父组件的方法)

效果预览

在这里插入图片描述

弹出的内容

src\pages\goods\components\ServicePanel.vue

<script setup lang="ts">
// 子组件调父组件的方法
const emit = defineEmits<{
     
  (event: 'close'): void
}>()
</script>

<template>
  <view class="service-panel">
    <!-- 关闭按钮 -->
    <text class="close icon-close" @tap="emit('close')"></text>
    <!-- 标题 -->
    <view class="title">服务说明</view>
    <!-- 内容 -->
    <view class="content">
      <view class="item">
        <view class="dt">无忧退货</view>
        <view class="dd">
          自收到商品之日起30天内,可在线申请无忧退货服务(食品等特殊商品除外)
        </view>
      </view>
      <view class="item">
        <view class="dt">快速退款</view>
        <view class="dd">
          收到退货包裹并确认无误后,将在48小时内办理退款,
          退款将原路返回,不同银行处理时间不同,预计1-5个工作日到账
        </view>
      </view>
      <view class="item">
        <view class="dt">满88元免邮费</view>
        <view class="dd">
          单笔订单金额(不含运费)满88元可免邮费,不满88元, 单笔订单收取10元邮费
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss">
.service-panel {
     
  padding: 0 30rpx;
  border-radius: 10rpx 10rpx 0 0;
  position: relative;
  background-color: #fff;
}

.title {
     
  line-height: 1;
  padding: 40rpx 0;
  text-align: center;
  font-size: 32rpx;
  font-weight: normal;
  border-bottom: 1rpx solid #ddd;
  color: #444;
}

.close {
     
  position: absolute;
  right: 24rpx;
  top: 24rpx;
}

.content {
     
  padding: 20rpx 20rpx 100rpx 20rpx;

  .item {
     
    margin-top: 20rpx;
  }

  .dt {
     
    margin-bottom: 10rpx;
    font-size: 28rpx;
    color: #333;
    font-weight: 500;
    position: relative;

    &::before {
     
      content: '';
      width: 10rpx;
      height: 10rpx;
      border-radius: 50%;
      background-color: #eaeaea;
      transform: translateY(-50%);
      position: absolute;
      top: 50%;
      left: -20rpx;
    }
  }

  .dd {
     
    line-height: 1.6;
    font-size: 26rpx;
    color: #999;
  }
}
</style>

页面导入并使用

import ServicePanel from './components/ServicePanel.vue'

// uni-ui 弹出层组件 ref
const popup = ref<{
   
  open: (type?: UniHelper.UniPopupType) => void
  close: () => void
}>()

const openPopup = () => {
   
  // 打开弹出层
  popup.value?.open()
}
<view @tap="openPopup('service')" class="item arrow">
  <text class="label">服务</text>
  <text class="text ellipsis"> 无忧退 快速退款 免费包邮 </text>
</view>
<!-- uni-ui 弹出层 -->
<uni-popup ref="popup" type="bottom" background-color="#fff">
  <ServicePanel  @close="popup?.close()" />
</uni-popup>

相关推荐

  1. uniapp扩展组件uni-popup 自动打开

    2023-12-09 10:18:04       21 阅读
  2. vue3组件组件方法

    2023-12-09 10:18:04       12 阅读
  3. Vue3+Ant Design 组件调用组件方法

    2023-12-09 10:18:04       13 阅读
  4. vue3组件调用组件方法

    2023-12-09 10:18:04       12 阅读
  5. vue组件调用组件方法

    2023-12-09 10:18:04       33 阅读
  6. Vue.js 中组件调用组件方法

    2023-12-09 10:18:04       35 阅读
  7. vue3中如何组件中使用框,组件中关闭

    2023-12-09 10:18:04       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-09 10:18:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-09 10:18:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-09 10:18:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-09 10:18:04       20 阅读

热门阅读

  1. mysql怎么优化查询?

    2023-12-09 10:18:04       30 阅读
  2. HTB Devvortex

    2023-12-09 10:18:04       33 阅读
  3. 理解chatGPT的Function calling

    2023-12-09 10:18:04       34 阅读
  4. kafka主题分区副本集群的概念

    2023-12-09 10:18:04       38 阅读
  5. 通讯app:

    2023-12-09 10:18:04       37 阅读