uniapp评论弹窗

效果图

代码

template

xml 复制代码
<template>
  <view>
    <view class="comment-button" @click="isShowCommentDialog = true">
      写评论
    </view>

    <!-- 遮罩层 -->
    <view v-if="isShowCommentDialog" class="mask" @click="handleClose" ></view>
    <!-- 弹窗主体 -->
    <view v-if="isShowCommentDialog" class="dialog-container">
      <view class="dialog-content">
        <view class="title">请输入评论</view>

        <!-- 评论输入框 -->
        <textarea 
          v-model="commentContent" 
          class="comment-input"
          placeholder="请输入您的宝贵意见(500字以内)"
          :maxlength="500"
          @input="handleInputChange"
        />

        <!-- 清空按钮 -->
        <view 
          class="clear-button"
          v-if="commentContent.length > 0"
          @click="commentContent = ''"
        >
          清空
        </view>

        <!-- 字数统计 -->
        <view class="word-count">
          {{ commentContent.length }}/500
        </view>

        <!-- 操作按钮组 -->
        <view class="button-group">
          <view 
            class="button cancel-button" 
            @click="handleClose"
          >
            取消
          </view>
          <view 
            class="button confirm-button" 
            :class="{ 'disabled': !commentContent.trim }"
            @click="handleSubmit"
          >
            确认提交
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

script

xml 复制代码
<script>
export default {
  data() {
    return {
      // 弹窗显示状态
      isShowCommentDialog: false, 
      // 评论内容
      commentContent: '', 
    }
  },
  methods: {
    // 输入内容变化处理
    handleInputChange() {
      // 可在此处添加输入格式校验逻辑
    },

    // 提交评论
    handleSubmit() {
      if (this.commentContent.trim) {
        // 提交逻辑(示例:打印到控制台)
        console.log('提交的评论内容:', this.commentContent)
        this.handleClose
      }
    },

    // 关闭弹窗
    handleClose() {
      this.isShowCommentDialog = false
      // this.commentContent = ''
    }
  }
}
</script>

style

xml 复制代码
<style>
.comment-button {
  padding: 10rpx 20rpx;
  background-color: #409eff;
  color: #fff;
  border-radius: 10rpx;
  text-align: center;
  margin: 20rpx;
}

.mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 998;
}

.dialog-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 500rpx;
  background-color: #fff;
  border-radius: 20rpx;
  z-index: 999;
  animation: dialogSlide 0.3s ease-out;
}

@keyframes dialogSlide {
  from { opacity: 0; transform: translate(-50%, -40%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.dialog-content {
  padding: 30rpx;
  position: relative;
}

.title {
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  text-align: center;
}

.comment-input {
  width: 100%;
  height: 200rpx;
  padding: 20rpx;
  border: 1px solid #e5e5e5;
  border-radius: 10rpx;
  font-size: 28rpx;
  box-sizing: border-box;
}

.clear-button {
  position: absolute;
  right: 80rpx;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-size: 24rpx;
  padding: 10rpx;
  border: 1rpx solid #f5f5f5;
}

.word-count {
  text-align: right;
  color: #999;
  margin: 10rpx 0;
  font-size: 24rpx;
}

.button-group {
  display: flex;
  justify-content: space-between;
  margin-top: 20rpx;
}

.button {
  flex: 1;
  padding: 15rpx 0;
  border-radius: 10rpx;
  text-align: center;
  font-size: 28rpx;
  transition: all 0.2s;
}

.cancel-button {
  background-color: #f5f5f5;
  color: #666;
}

.confirm-button {
  background-color: #409eff;
  color: #fff;
}

.confirm-button.disabled {
  background-color: #999;
  cursor: not-allowed;
}

</style>
相关推荐
dly_blog4 分钟前
Vue 响应式陷阱与解决方案(第19节)
前端·javascript·vue.js
消失的旧时光-194318 分钟前
401 自动刷新 Token 的完整架构设计(Dio 实战版)
开发语言·前端·javascript
console.log('npc')30 分钟前
Table,vue3在父组件调用子组件columns列的方法展示弹窗文件预览效果
前端·javascript·vue.js
用户479492835691539 分钟前
React Hooks 的“天条”:为啥绝对不能写在 if 语句里?
前端·react.js
我命由我123451 小时前
SVG - SVG 引入(SVG 概述、SVG 基本使用、SVG 使用 CSS、SVG 使用 JavaScript、SVG 实例实操)
开发语言·前端·javascript·css·学习·ecmascript·学习方法
用户47949283569151 小时前
给客户做私有化部署,我是如何优雅搞定 NPM 依赖管理的?
前端·后端·程序员
C_心欲无痕2 小时前
vue3 - markRaw标记为非响应式对象
前端·javascript·vue.js
qingyun9892 小时前
深度优先遍历:JavaScript递归查找树形数据结构中的节点标签
前端·javascript·数据结构
熬夜敲代码的小N2 小时前
Vue (Official)重磅更新!Vue Language Tools 3.2功能一览!
前端·javascript·vue.js
90后的晨仔2 小时前
用 Python 脚本一键重命名序列帧图片的名称
前端