- 需求的场景描述(希望解决的问题)
在编写完一个云函数在页面中调用的时候出错提示Cannot read property ‘callFunction’ of undefined,各位有知道如何解决的吗?
调用的代码:
wx.cloud.callFunction({
name: ‘smzdm’,
data: {
category: ‘diannaoshuma’
}
}).then(r => { console.log® })
云函数:
// 云函数入口文件
const cloud = require(‘wx-server-sdk’)
cloud.init()
// 云函数入口函数
const request = require(‘request’)
const cheerio = require(‘cheerio’)
exports.main = async (event = {}) => {
let category = event.category || ‘diannaoshuma’
return new Promise((resolve, reject) => {
request.get(`https://m.smzdm.com/fenlei/${category}/`, (e, req, body) => {
if (!e && req.statusCode === 200) {
const $ = cheerio.load(body)
const result = []
$(’.card-group-list’).each((i, v) => {
let $v = $(v)
let title = $v.find(’.zm-card-title’).text().trim()
let image = $v.find(’.zm-card-media img’).attr(‘src’)
let mall = $v.find(’.card-mall’).text().trim()
result.push({
title,
image,
mall
})
})
resolve(result)
}
})
})
}
- 希望提供的能力