demo.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <view>
  3. <canvas style="width: 750px; height: 200px;" canvas-id="firstCanvas" id="firstCanvas"></canvas>
  4. <!-- <canvas style="width: 400px; height: 500px;" canvas-id="secondCanvas" id="secondCanvas"></canvas> -->
  5. <!-- <canvas style="width: 400px; height: 500px;" canvas-id="secondCanvas" id="secondCanvas" @error="canvasIdErrorCallback"></canvas> -->
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. onReady: function (e) {
  11. var context = uni.createCanvasContext('firstCanvas')
  12. context.setStrokeStyle("#00ff00")
  13. context.setLineWidth(5)
  14. context.rect(0, 0, 200, 200)
  15. context.stroke()
  16. // context.setStrokeStyle("#ff0000")
  17. // context.setLineWidth(2)
  18. // context.moveTo(160, 100)
  19. // context.arc(100, 100, 60, 0, 2 * Math.PI, true)
  20. // context.moveTo(140, 100)
  21. // context.arc(100, 100, 40, 0, Math.PI, false)
  22. // context.moveTo(85, 80)
  23. // context.arc(80, 80, 5, 0, 2 * Math.PI, true)
  24. // context.moveTo(125, 80)
  25. // context.arc(120, 80, 5, 0, 2 * Math.PI, true)
  26. // context.stroke()
  27. context.draw()
  28. },
  29. methods: {
  30. canvasIdErrorCallback: function (e) {
  31. console.error(e.detail.errMsg)
  32. }
  33. }
  34. }
  35. </script>