在测试小程序问答回帖时,总出现“评论内容不能为空”求助!
我的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;
}
// 格式化评论内容,方便二次开发和重写 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']); } }