在測試小程序問答回帖時,總出現(xiàn)“評論內容不能為空”求助!
我的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;
}
請教具體怎么弄?回復@湖北人
備注解決方法:dayrui\App\Wenda\Controllers\Comment.php
改為以下代碼:
// 格式化評論內容,方便二次開發(fā)和重寫 public function _safe_replace($data) { // 檢查 $_POST['data']['content'] 是否存在或為空 if (empty($_POST['data']['content'])) { return $data; // 返回原始數(shù)據(jù) } // 處理內容 return str_replace(['<p><br/></p>'], '', (string)$_POST['data']['content']); } }