小程序中问答模块在回帖时提示“评论内容不能为空”

迅睿框架 更新 2025-04-09 20:33:24 我爱迅睿CMS

在测试小程序问答回帖时,总出现“评论内容不能为空”求助!


我的API接口是:

// 提交评论
 postCommentUrl: function(id) {
 return CMS_API + '&s=wenda&m=post&c=comment&api_auth_code=' + wx.getStorageSync('member_auth') + '&api_auth_uid=' + wx.getStorageSync('member_uid') + '&id=' + id;
 }, 

我的前端代码是:

<div class="comment-input">
        <input
          v-model="newComment"
          placeholder="请输入评论内容"
          class="input-box"
        />
        <button @tap="submitComment" class="submit-btn">提交</button>
      </div>
    </div>

JS部分:

// 提交评论
    submitComment() {
      var self = this;
      if (self.newComment.trim() === "") {
        wx.showToast({
          title: "评论内容不能为空",
          icon: "none",
        });
        return;
      }


方案

  • 湖北人 #1 · 2025-03-03 15:55:32
    说明没有获取到控件值了
  • 我爱迅睿CMS #2 · 2025-03-03 15:57:43
    请教具体怎么弄?湖北人
  • 我爱迅睿CMS #3 · 2025-04-09 20:32:42
    满意答案
    备注解决方法:dayrui\App\Wenda\Controllers\Comment.php改为以下代码:
     // 格式化评论内容,方便二次开发和重写
    public function _safe_replace($data) {
        // 检查 $_POST['data']['content'] 是否存在或为空
        if (empty($_POST['data']['content'])) {
            return $data; // 返回原始数据
        }
        // 处理内容
        return str_replace(['<p><br/></p>'], '', (string)$_POST['data']['content']);
    }
    }
  • 我爱迅睿CMS #4 · 2025-04-09 20:33:24
    @我爱迅睿CMS:通过查阅社区知识点,已成功解决

迅睿系统漏洞

百度AI批量检测敏感词
百度AI批量检测敏感词(2026-10-26)
优化长任务超时问题
泛解析站群系统
泛解析站群系统(2026-10-26)
添加子站时设置模板
GEO系统
GEO系统(2026-10-26)
修复抖音图文会话不持久:扩大 Cookie 域、会话 Cookie ...
GeoSeo收录宝
GeoSeo收录宝(2026-10-25)
优化插件日志等小细节 1 优化 爬虫监控月统计超200万数据容易...
迅睿工具箱
迅睿工具箱(2026-10-24)
修正页面显示样式
秒变内部站
秒变内部站(2026-10-23)
全站只有管理员身份可以访问
GeoSeo工具箱
GeoSeo工具箱(2026-10-23)
Schema信息数据兜底
AI文章生成器
AI文章生成器(2026-10-23)
关键词批量录入
网站监控
网站监控(2026-10-23)
状态码大于0,即认为服务器在线