为什么我this.data.bookname获取的值是undefined?

发布于 8 年前作者 txia13124 次浏览最后编辑 8 年前来自 issues

两个都是undefined

4 回复
mingfan
mingfan1 楼6 年前

你还没赋值就去取值了吧?

blei
blei2 楼6 年前

onShow: async function(){

if(!this.data.bookInfo || !this.data.bookInfo.fileID){

var res = await db.collection(‘file’).where({

book: ‘书名’

}).get()

this.setData({

bookInfo: res.data[0]

})

}

}

yangxue
yangxue3 楼6 年前

你是异步赋值  同步取吧  这能取得到么

ocui
ocui4 楼6 年前

看一下控制台AppData有没有值,没有值,当然就取不出来了。注意一下this