最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue使用鼠標(biāo)在Canvas上繪制矩形

 更新時間:2020年12月24日 09:58:27   作者:小諸葛的博客  
這篇文章主要介紹了Vue使用鼠標(biāo)在Canvas上繪制矩形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Vue使用鼠標(biāo)在Canvas上繪制矩形的具體代碼,供大家參考,具體內(nèi)容如下

1.代碼

<template>
 <div class="test" style="background-color: burlywood;">
 <canvas id="myCanvas" ref="myCanvas"
   width="460" height="240" @mousedown="mousedown" @mouseup="mouseup" @mousemove="mousemove">
 </canvas>
 </div>
</template>
 
<script>
 export default {
 name:"hello-world",
 data() {
  return {
  flag: false,
  x: 0,
  y: 0
  };
 },
 watch: {},
 computed: {},
 methods: {
  mousedown(e){
  console.log("鼠標(biāo)落下");
  this.flag = true;
  this.x = e.offsetX; // 鼠標(biāo)落下時的X
  this.y = e.offsetY; // 鼠標(biāo)落下時的Y
  },
  mouseup(e){
  console.log("鼠標(biāo)抬起");
  this.flag = false;
  },
  mousemove(e){
  console.log("鼠標(biāo)移動");
  this.drawRect(e);
  },
  drawRect(e){
  if(this.flag){
   console.log("繪制圖形");
   const canvas = this.$refs.myCanvas;
   var ctx = canvas.getContext("2d");
   let x = this.x;
   let y = this.y;
 
   ctx.clearRect(0,0,canvas.width,canvas.height);
   ctx.beginPath();
 
   //設(shè)置線條顏色,必須放在繪制之前
   ctx.strokeStyle = '#00ff00';
   // 線寬設(shè)置,必須放在繪制之前
   ctx.lineWidth = 1;
 
   ctx.strokeRect(x,y,e.offsetX-x,e.offsetY-y);
  }
  }
 },
 created() {
 
 },
 mounted() {
 
 }
 };
</script>
 
<style scoped>
 #myCanvas{
 background-color: forestgreen;
 background-image:url('../bg.jpg');
 }
</style>

2.運(yùn)行截圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

林西县| 固始县| 库车县| 罗甸县| 黑龙江省| 东港市| 荣成市| 新龙县| 扎囊县| 两当县| 镇沅| 绥宁县| 佛山市| 德庆县| 大英县| 揭西县| 临颍县| 姜堰市| 大庆市| 保德县| 和田市| 乐至县| 上饶县| 侯马市| 阿拉尔市| 凤庆县| 威海市| 泰宁县| 保德县| 麟游县| 岳阳市| 西乌珠穆沁旗| 敦煌市| 凤山市| 横峰县| 武威市| 罗平县| 上虞市| 天峨县| 沅陵县| 从江县|