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');
});
}
在控制台打印一下返回的数据是否有值
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;
}
博主,问题解决了吗?我也遇到同样的问题。