简体   繁体   English

道具编号不会改变时间

[英]prop number won't change the time

I'm building an audio player with basic functionalities like backward, play and forward button.我正在构建一个具有后退、播放和前进按钮等基本功能的音频播放器。 The player does the backward functionality fine but the forward doesn't work even though I set the same variable for both.播放器的向后功能很好,但即使我为两者设置了相同的变量,向前也不起作用。 What could be the reason for this anomaly?这种异常的原因可能是什么?

props: {
    skipTime: {
        type: Number
    }
  },
  methods: {
    prev() {
      this.$refs.audio.currentTime -= this.skipTime;
    },
    next(){
      this.$refs.audio.currentTime += this.skipTime;
    }

however this works然而这有效

props: {
    skipTime: {
        type: Number
    }
  },
  methods: {
    prev() {
      this.$refs.audio.currentTime -= this.skipTime;
    },
    next(){
      this.$refs.audio.currentTime += 5;
    }

It seems that this.$refs.audio.currentTime += this.skipTime;似乎this.$refs.audio.currentTime += this.skipTime; is doing string concatenation instead of sum, try out:正在做字符串连接而不是求和,试试:

  this.$refs.audio.currentTime += +this.skipTime;

, ,

 this.$refs.audio.currentTime += Number(this.skipTime);

or或者

this.$refs.audio.currentTime =Number(this.$refs.audio.currentTime )+ Number(this.skipTime);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM