canvas.js 791 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const example = require('./example.js')
  2. Page({
  3. onShareAppMessage() {
  4. return {
  5. title: '创建画布',
  6. path: 'page/API/pages/canvas/canvas'
  7. }
  8. },
  9. onLoad() {
  10. this.context = wx.createContext()
  11. const methods = Object.keys(example)
  12. this.setData({
  13. methods
  14. })
  15. const that = this
  16. methods.forEach(function (method) {
  17. that[method] = function () {
  18. example[method](that.context)
  19. const actions = that.context.getActions()
  20. wx.drawCanvas({
  21. canvasId: 'canvas',
  22. actions
  23. })
  24. }
  25. })
  26. },
  27. toTempFilePath() {
  28. wx.canvasToTempFilePath({
  29. canvasId: 'canvas',
  30. success(res) {
  31. console.log(res)
  32. },
  33. fail(res) {
  34. console.log(res)
  35. }
  36. })
  37. }
  38. })