formSubmit: function(e) {
console.log('图片:', that.data.images)
that.data.content = e.detail.value['input-content'];
if(Object.keys(that.data.user).length===0){
that.jugdeUserLogin();
}
else{
if (that.data.images.lengt > 0){
that.saveDataToServer();
}else if(that.data.content.trim() != ''){
that.saveDataToServer();
console.log("进行内容保存")
} else if(that.data.srcVideo.trim()!= ''){
that.saveDataToServer();
}else{
wx.showToast({
icon: 'none',
title: '写点东西吧',
})
}
}
},
/**
* 保存到发布集合中
*/
saveDataToServer: function(event) {
console.log("updata添加数据")
const db = wx.cloud.database()
db.collection('topic').add({
// data 字段表示需新增的 JSON 数据
data: {
content: that.data.content,
date: new Date(),
images: that.data.images,
user: that.data.user,
isLike:0,
srcVideo:that.data.srcVideo,
count:0,
label:that.data.label,
collect:0,
},
点第一次执行了console.log('图片:', that.data.images)
然后停住了,第二次才又重头进行了一遍
那是因为第二次才满足if的条件
应该能看明白我的意思吧。。。我刚接触小程序,还请各位海涵