【问题标题】:prop number won't change the time道具编号不会改变时间
【发布时间】:2021-01-20 15:01:35
【问题描述】:

我正在构建一个具有后退、播放和前进按钮等基本功能的音频播放器。播放器的向后功能很好,但即使我为两者设置了相同的变量,向前也不起作用。这种异常的原因可能是什么?

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

不管怎样都行

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

【问题讨论】:

  • 您确定设置了this.skipTime 吗?听起来不是。
  • 对不起,是的,那里有一个错字。但是我为向后和向前设置了相同的跳过时间,只有向后工作,向前不起作用。道具只能设置一次吗? @MarkReed
  • 我假设您的实际代码中有大括号..
  • 是的,我有那些@MarkReed

标签: javascript vue.js vuejs2 vuejs3


【解决方案1】:

看来this.$refs.audio.currentTime += this.skipTime; 是在做字符串连接而不是求和,试试看:

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

,

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2018-08-09
    • 2020-04-28
    • 2019-07-27
    相关资源
    最近更新 更多