Vue solution:
You can use $ once , which will listen for the event, but only once.
Listen to a custom event, but only once. The listener will be deleted after its launch for the first time.
You just need to add .once to @change , as shown below:
<div @change.once="handleRotate"></div> <script> export default { </script>
Check out the demo if it's in the fiddle .
Old answer:
If you don't want to have the initial value set for rotate , you can have another variable: hasRotated to keep track of whether the rotation has changed or not. The hasRotated value is hasRotated true, after the rotation has been changed, set hasRotated to false, as shown below:
<div @change="handleRotate"></div> <script> export default { data: { rotate: 123, hasRotated: false }, methods: { handleRotate () { if(this.hasRotated){ this.rotate = this.rotate + this.getRotateAngle(e.clientX, e.clientY) this.hasRotated = false } } } } </script>
source share