uni-app:实现右侧弹窗

效果:

代码:

html 复制代码
<template>
  <view class="container">
    <button @click="showModal = true">点击按钮</button>
    <view class="modal-overlay" v-if="showModal" @click="closeModal"></view>
    <view class="modal-container" :class="{ active: showModal }">
      <!-- 右侧弹窗的内容 -->
      <view class="modal-content">
        <!-- 内容区域 -->
        <text>这是右侧弹窗的内容</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      showModal: false, // 控制弹窗显示与隐藏
    };
  },
  methods: {
    closeModal() {
      this.showModal = false;
    },
  },
};
</script>

<style>
.container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.modal-container {
  position: fixed;
  top: 0;
  right: -100%; /* 初始时隐藏弹窗 */
  width: 300px;
  height: 100%;
  background-color: #fff;
  z-index: 1000;
  transition: right 0.3s ease;
}

.modal-container.active {
  right: 0; /* 显示弹窗 */
}

.modal-content {
  padding: 20px;
}
</style>
相关推荐
IT_陈寒20 小时前
React的这个渲染问题连官方文档都没说清楚
前端·人工智能·后端
追逐时光者21 小时前
别再满网找零散工具了,腾讯 QQ 浏览器这个“帮小忙”工具箱真能省时间
前端·后端
Asmewill1 天前
grep&curl命令学习笔记
前端
spmcor1 天前
身份证读卡“无感登录”方案实践:从手动点击到自动检测
uni-app
stringwu1 天前
Flutter 开发必备:MVI 架构的高效实现指南
前端·flutter
用户2136610035721 天前
Vue2组件化开发与父子通信
前端·vue.js
Momo__1 天前
TypeScript satisfies 操作符——比 as 更安全的类型守门员
前端·typescript
用户2136610035721 天前
Vue2事件系统与指令进阶
前端·vue.js
labixiong1 天前
实现一个能跑的迷你版Promise(一)
前端·javascript·面试
Csvn1 天前
`??` 和 `||` 搞混,线上用户头像全挂了
前端