formSubmit: function (event) {
var pics = this.data.pics;
console.log(pics);
var piccloud=[];
for (var i = 0; i
var picid = Math.random();
console.log(picid)
var pic=pics[i];
console.log(pic);
wx.cloud.uploadFile({
cloudPath: picid+'.png',
filePath: pic, // 微信小程序临时文件路径
success: res => {
piccloud.push(res.fileID)
console.log(piccloud)
// get resource ID
// picloud[i]=res.fileID
},
fail: err => {
}
})
console.log(piccloud);
}
》》》》》》为什么这后面的的代码,在wx.cloud.upload之前就执行了呢?
console.log(100)
var that=this;
var db=wx.cloud.database();
db.collection('test').add({
data:{
title: event.detail.value.title,
content: event.detail.value.content,
photo: piccloud
},success:res=>{
console.log(100000)
wx.showToast({
title: '发布成功', icon: 'success',
});
//发布成功后,返回首页,注意道js文件要../返回到first页面
wx.reLaunch({
url: "../first/first",sucess:res=>{ }
})
}
})
},
微信小程序开发问题解答
微信小程序开发者回答:
wx.cloud.upload 是异步 想要之后再运行后面的代码 放upload 的success回调里
本文网址:http://www.91bianli.com/weixinxiaochengxu/41500.html