加上每秒的setInterval数

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>
评论
vvelit
vvelit

You need to assign the value back to this.sHand:

this.sHand = this.sHand + 6
点赞
评论
cut
cut

You have to reassign the value to this.sHand after incrementing it.

created(){
    setInterval(() => {
        this.sHand = this.sHand + 6
        // or this.sHand += 6
    },1000)
  }

点赞
评论
Rabbit_19C
Rabbit_19C

您忘记了作业。

this.sHand++ actually means:

this.sHand = this.sHand + 1

因此,它是递增和分配。

this.sHand += 6

会做。

点赞
评论