GoodCoder666的个人博客

使用微信小程序-云开发时报错: Error: errCode: -401003 api parameter type error | errMsg: parameter.data should ...

2020-02-02 · 1 min read
微信小程序 Bug/错误解决

错误

Uncaught (in promise) thirdScriptError
errCode: -401003 api parameter type error | errMsg: parameter.data should be object instead of undefined;
Error: errCode: -401003 api parameter type error | errMsg: parameter.data should be object instead of undefined;
at new u (...)
...

错误原因

错误写法

wx.cloud.init({
  env: '我的云ID',
  traceUser: true
})

const db = wx.cloud.database()
const people = db.collection('people')

people.add({ // <- 报错
    'name': 'OnePerson',
    'score': 15
})

正确写法

wx.cloud.init({
  env: '我的云ID',
  traceUser: true
})

const db = wx.cloud.database()
const people = db.collection('people')

people.add({
	data: { // 必须加上data!
		'name': 'OnePerson',
		'score': 15
	}
})