123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // pages/addFunction/addFunction.js
- const code = `// 云函数入口函数
- exports.main = async (event, context) => {
- console.log(event)
- console.log(context)
- return {
- sum: event.a + event.b
- }
- }`
- Page({
- data: {
- result: '',
- canIUseClipboard: wx.canIUse('setClipboardData'),
- },
- onLoad: function (options) {
- },
- copyCode: function() {
- wx.setClipboardData({
- data: code,
- success: function () {
- wx.showToast({
- title: '复制成功',
- })
- }
- })
- },
- testFunction() {
- wx.cloud.callFunction({
- name: 'sum',
- data: {
- a: 1,
- b: 2
- },
- success: res => {
- wx.showToast({
- title: '调用成功',
- })
- this.setData({
- result: JSON.stringify(res.result)
- })
- },
- fail: err => {
- wx.showToast({
- icon: 'none',
- title: '调用失败',
- })
- console.error('[云函数] [sum] 调用失败:', err)
- }
- })
- },
- })
|