Reputation: 287
I want my sHand
to add 6 per second but it works only once, If I try to do something like this: this.sHand++
it works fine and adds 1 degrees per second but I want 6 instead of 1 any solutions?
data:{
sHand: 30
},
computed:{
style(){
return { transform: 'rotate(' + this.sHand + 'deg)'}
}
},
created(){
setInterval(() => {
this.sHand + 6 // not working :/
},1000)
}
<div :style="style" class="secondhand"></div>
Upvotes: 0
Views: 42
Reputation: 6837
You have to assign the value to this.sHand
after incrementing it.
created(){
setInterval(() => {
this.sHand = this.sHand + 6
// or this.sHand += 6
},1000)
}
Upvotes: 1
Reputation: 932
You forgot the assignment.
this.sHand++
actually means:
this.sHand = this.sHand + 1
So, it's incrementing and the assigning.
this.sHand += 6
will do.
Upvotes: 1
Reputation: 7271
You need to assign the value back to this.sHand
:
this.sHand = this.sHand + 6
Upvotes: 1