收藏
回答

Setting data field "homeworkList" to undefined ?

gethomeworklist: function () {

      wx.cloud.callFunction({

        name: "gethomeworklist",

        success: res => {

          if (res.result.success{

            this.setData({ homeworkList: res.result.data });

          } else {

            wx.showToast({

              title: "获取作业列表失败",

              icon: "none"

            });

          }

        },

        fail: err => {

          console.error("调用云函数失败:", err);

        }

      });

    },



const cloud = require("wx-server-sdk");

cloud.init({

  env: "mini-0ggdngk79e7669b3"

});


const db = cloud.database();


exports.main = async (event, context) => {

  try {

    const homeworkList = await db.collection('homework').field({

      title: true,

      description: true,

      deadline: true,

      imageURLs: true,

      fileURLs: true

    }).get();


    return {

      success: true,

      message: "获取作业列表成功",

      data: homeworkList.data

    };

  } catch (error{

    console.error("获取作业列表失败:", error);

    return {

      success: false,

      message: "获取作业列表失败",

      error: error

    };

  }

};



报错:Setting data field "homeworkList" to undefined is invalid.怎么解决


回答关注问题邀请回答
收藏
登录 后发表内容