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>
相关推荐
馬致远4 分钟前
Vue TodoList 待办事项小案例(代码版)
前端·javascript·vue.js
一字白首20 分钟前
Vue 进阶,Vuex 核心概念 + 项目打包发布配置全解析
前端·javascript·vue.js
栀秋66623 分钟前
从前端送花说起:HTML敲击乐与JavaScript代理模式的浪漫邂逅
前端·javascript·css
刘同学有点忙24 分钟前
国际化语言包与Excel自动化双向转换方案
前端
bm90dA24 分钟前
前端小记:Vue3引入mockjs开发
前端
渔_24 分钟前
SCSS 实战指南:从基础到进阶,让 CSS 编写效率翻倍
前端
Syron25 分钟前
为什么微应用不需要配置 try_files?
前端
前端老宋Running26 分钟前
别再写 API 路由了:Server Actions 才是全栈 React 的终极形态
前端·react.js·架构
王小酱27 分钟前
Cursor 的 Debug模式的核心理念和使用流程
前端·cursor
前端老宋Running27 分钟前
跟“白屏”说拜拜:用 Next.js 把 React 搬到服务器上,Google 爬虫都要喊一声“真香”
前端·react.js·架构