项目场景:
vue-cropper git:https://github.com/xyxiao001/vue-cropper
问题描述
在使用vue-cropper旋转功能时,内部方法默认每次旋转±1 同步到css也就是90°
无法做出自定义任意角度旋转
<Button size="mini" type="danger" plain @click="rotateLeft">旋转</Button>
rotateLeft () {
this.$refs.cropper.rotateLeft()
}
// 内部方法 向左边旋转
rotateLeft() {
this.rotate = this.rotate <= -3 ? 0 : this.rotate - 1;
},
ctx.rotate((rotate * 90 * Math.PI) / 180);
解决方案:
想要自定义角度旋转,就不能直接使用内部方法进行操作,而是直接修改this.rotate
的值,因为this.rotate
的值每增加1就是旋转90度,旋转任意角度就是 任意角度/90
<Button size="mini" type="danger" plain @click="rotateLeft">旋转</Button>
rotateLeft () {
//this.$refs.cropper.rotateLeft()
//旋转100度
this.$refs.cropper.rotate=this.$refs.cropper.rotate+100/90;
//每次递增旋转9度
this.$refs.cropper.rotate=this.$refs.cropper.rotate+9/90;
}
// 内部方法 向左边旋转
rotateLeft() {
this.rotate = this.rotate <= -3 ? 0 : this.rotate - 1;
},
ctx.rotate((rotate * 90 * Math.PI) / 180);