markLine.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!--
  2. * User: CHT
  3. * Date: 2020/6/27
  4. * Time: 15:55
  5. -->
  6. <template>
  7. <canvas
  8. ref="markLine"
  9. class="super-flow__mark-line">
  10. </canvas>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. width: {
  16. type: Number,
  17. default: 0
  18. },
  19. height: {
  20. type: Number,
  21. default: 0
  22. },
  23. markLine: Array,
  24. markColor: String
  25. },
  26. mounted () {
  27. this.$refs.markLine.height = this.height
  28. this.$refs.markLine.width = this.width
  29. this.draw()
  30. },
  31. methods: {
  32. draw () {
  33. const ctx = this.$el.getContext('2d')
  34. ctx.clearRect(0, 0, this.width, this.height)
  35. ctx.strokeStyle = this.markColor
  36. ctx.lineWidth = 1
  37. ctx.setLineDash([4, 2])
  38. this.markLine.forEach(([start, end]) => {
  39. ctx.beginPath()
  40. ctx.moveTo(...start)
  41. ctx.lineTo(...end)
  42. ctx.stroke()
  43. })
  44. }
  45. },
  46. watch: {
  47. markLine () {
  48. this.draw()
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="less">
  54. .super-flow__mark-line {
  55. position : absolute;
  56. z-index : 0;
  57. border: 1px solid transparent;
  58. }
  59. </style>