加上每秒的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
    

    会做。