OhhhhhhhhhhhO 2022-06-14 23:33 采纳率: 0%
浏览 47

为什么无法获取云数据库数据

import { config, cdnBase } from '../../config/index';

function genSwiperImageList() {
wx.cloud.database().collection('good')
.get({
success(res) {
this.setData({
genSwiperImageList:res.data
})
console.log('获取成功')
},
fail(){
console.log("获取失败")
}

});
return genSwiperImageList;
}

/** 获取首页数据 */
function mockFetchHome() {
const { delay } = require('../_utils/delay');

return delay().then(() => {
return {
swiper: genSwiperImageList(),
tabList: [
{
text: '外套',
key: 0,
},
{
text: '上衣',
key: 1,
},
{
text: '下装',
key: 2,
},
{
text: '鞋子',
key: 3,
},
{
text: '包包',
key: 4,
},
{
text: '家纺',
key: 5,
},

  ],
  activityImg: `${cdnBase}/activity/banner.png`,
};

});
}

/** 获取首页数据 */
export function fetchHome() {
if (config.useMock) {
return mockFetchHome();
}
return new Promise((resolve) => {
resolve('real api');
});
}

  • 写回答

2条回答 默认 最新

  • 前端陈皮喵 2022-06-15 14:54
    关注

    在控制台打印一下返回的数据是否有值

    function genSwiperImageList() {
    wx.cloud.database().collection('good')
    .get({
    success(res) {
    console.log(res.data)         //打印
    this.setData({
    genSwiperImageList:res.data
    })
    console.log('获取成功')
    },
    fail(){
    console.log("获取失败")
    }
    
    });
    return genSwiperImageList;
    }
    
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 6月14日