收藏
回答

textarea组件没有输入内容一直显示正在发表中?

如图,textarea组件,如果没有输入内容,就一直显示正在发表中...,打印的结果是undefined,这是什么问题?

wxml代码:

<form bindsubmit="onReleaseEvent">
  <view class="carpool-group">
    <view class="carpool-title">备注</view>
    <textarea class="content" placeholder="请输入您要补充的内容" />
  </view>
  <button class="btn" formType="submit">提交</button>
</form>

js代码:

// 日期转换函数
    convertDate(dateStr) {
        const now = new Date();
        const dateArr = dateStr.split('-');
        let convertedDate;
        if (dateArr.length === 3) {
            // 如果是具体日期格式,如 "2024-11-20"
            convertedDate = new Date(dateArr[0], dateArr[1] - 1, dateArr[2]);
        } else {
            // 如果是今天、明天、后天
            const dayOffset = ['今天''明天''后天'].indexOf(dateStr);
            if (dayOffset !== -1) {
                convertedDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + dayOffset);
            }
        }
        return convertedDate;
    },

    /**
     * 发布信息
     */
    onReleaseEvent(event) {
        const that = this;
        const carpool = that.data.carpool;
        const day = that.convertDate(that.data.day); // 转换日期
        if (!day) {
            wx.showToast({
                title"请选择日期",
                icon'none'
            });
            return;
        }
        console.log(day)
        const dateString = `${day.getFullYear()}-${(day.getMonth() + 1).toString().padStart(2'0')}-${day.getDate().toString().padStart(2'0')}`;
        const times = that.data.time;
        const startPoint = event.detail.value.startPoint;
        const goal = event.detail.value.goal;
        const car = event.detail.value.car;
        const peopleNumber = event.detail.value.peopleNumber;
        const phone = event.detail.value.phone;
        const content = event.detail.value.content;
        console.log('备注的内容',content);
        const pass = event.detail.value.pass;
        const weight = event.detail.value.weight;
        const ton = event.detail.value.ton;
        const tonsize = event.detail.value.tonsize;
        // 检查是否所有必填信息都已填写
        if (!carpool || !day || !times || !startPoint || !goal || !car || !peopleNumber || !phone) {
            wx.showToast({
                title"请填写相关信息",
                icon'none'
            });
            return;
        }
        wx.showLoading({
            title"正在发表中..."
        });
        wx.cloud.callFunction({
            name"wehicles",
            data: {
                carpool: carpool,
                day: dateString,
                times: times,
                startPoint: startPoint,
                goal: goal,
                car: car,
                peopleNumber: peopleNumber,
                phone: phone,
                content: content,
                pass: pass,
                weight: weight,
                ton: ton,
                tonsize: tonsize
            },
            successres => {
                const _id = res.result._id;
                if (_id) {
                    wx.hideLoading();
                    wx.showToast({
                        title"恭喜!发送成功!",
                    })
                    setTimeout(function () {
                        wx.switchTab({
                            url'/pages/index/index'
                        })
                    }, 800)
                } else {
                    wx.showToast({
                        title: res.result.errMsg,
                    })
                }
            }
        })
    },
回答关注问题邀请回答
收藏

1 个回答

  • 那一抹笑😃 穿透阳光
    那一抹笑😃 穿透阳光
    1天前

    应该是你的方法调用失败了,你这里,又没有失败的处理逻辑

    1天前
    有用 1
    回复 1
    • 蓝天☁
      蓝天☁
      1天前
      这是云函数的代码,截图是日志反馈的
      1天前
      回复
登录 后发表内容