get-wx-context.js 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // 参考文档:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/utils/getWXContext.html
  2. Page({
  3. onShareAppMessage() {
  4. return {
  5. title: 'WXContext',
  6. path: 'page/cloud/pages/get-wx-context/get-wx-context'
  7. }
  8. },
  9. data: {
  10. hasWXContext: false,
  11. wxContext: {},
  12. loading: false
  13. },
  14. getWXContext() {
  15. this.setData({
  16. loading: true
  17. })
  18. wx.cloud.callFunction({
  19. name: 'wxContext',
  20. data: {},
  21. success: res => {
  22. console.log('[云函数] [wxContext] wxContext: ', res.result)
  23. this.setData({
  24. hasWXContext: true,
  25. wxContext: res.result,
  26. loading: false
  27. })
  28. },
  29. fail: err => {
  30. console.error('[云函数] [wxContext] 调用失败', err)
  31. }
  32. })
  33. },
  34. clear() {
  35. this.setData({
  36. hasWXContext: false,
  37. wxContext: {}
  38. })
  39. }
  40. })