我这样写就报错了: Unexpected token ':'
如果不加await,那么返回的就是promiss,不能获得data
async generateUserId: function(flag = '') {
// const db = uniCloud.database()
const dbJQL = uniCloud.databaseForJQL({ // 获取JQL database引用,此处需要传入云对象的clientInfo
// clientInfo: this.getClientInfo()
})
// let res = dbJQL.collection('uni-id-users')
// .where({
// deviceid: "" + 1
// })
// .field('deviceid')
// .get()
let res = addDevice(dbJQL)
console.log(JSON.stringify(res))
// if(res.result.data.length > 0) {
// return res.result.data[0];
// }
// // 表示错误的
// return (MAX_USER_DEVICE_ID + randomInt()) + ""
return "success"
},
async function addDevice (dbJQL) {
let res = await dbJQL.collection('devices')
.where({
deviceid: "" + 1
})
.field('deviceid')
.get()
return res;
}
3 个回复
DCloud_uniCloud_WYQ
async generateUserId: function(flag = '') {
改成
generateUserId:async function(flag = '') {
DCloud_uniCloud_CRL
建议看下 Javascript 函数基础https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Functions
newPage (作者)
我想将第二个方法抽取到一个js文件中,这个时候,就无法进行等待执行了,所以不知道怎么处理