错误信息:
RequestError {type: "mySql is not a function", message: "登录态已过期"}
前端:
testCgi: function () {
util.showBusy(‘请求中…’)
var that = this
qcloud.request({
url: `${config.service.host}/weapp/demo`,
data:{
name:‘Mickey’
,sex:‘男’
}
,login: false
,success (result) {
util.showSuccess(‘请求成功完成’)
that.setData({
requestResult: JSON.stringify(result.data)
})
console.log(result.data)
},
fail (error) {
util.showModel(‘请求失败’, error)
console.log(‘request fail’, error)
}
})
}
demo.js这样写:
const {mySql} =require(’…/qcloud’)
module.exports=ctx=>{
var book={
id:3
,name:‘ecma6入门’
,price:99
}
mySql(‘cBooks’).insert(book)
ctx.state.data={
msg:“Hello World”
}
}