I'm handling a rotate even on change
:
<div @change="handleRotate"></div>
<script>
export default {
data: {
rotate = 0
},
methods: {
handleRotate () {
this.rotate = this.rotate + this.getRotateAngle(e.clientX, e.clientY)
}
}
}
</script>
Right now, the second this.rotate
runs on every change
. How can I do it so that the second this.rotate
is applied only the first time handleRotate
runs?
one simple solution would be to add a marker somewhat like this:
of course you would need to initiate this.rotated as false
If
rotate
start always at zero you can do:Solving it Vue way:
You can use $once, which will listen for a event but only once.
You just need to add
.once
to@change
like following:Check demo if this in the fiddle.
Old Answer:
If you do not want to have initial value set for
rotate
, you can have one more variable :hasRotated
to track whether rotate has been changed or not. Initially sethasRotated
to true, once rotate has been changed sethasRotated
to false, like following: