相关疑难解决方法(0)

具有HTML5音频属性的vuejs

我正在使用Vuejs制作音频控制面板,我想将currentTime属性绑定到一个computed值,所以我写

  computed: {
    'currentTime': {
      cache: false,
      get: function () {
        return document.getElementById('player').currentTime
      }
    }
  },
Run Code Online (Sandbox Code Playgroud)

这是我的audio标签:

  <audio :src="musicSrc" preload="auto" id="player">
    <p>Your browser does not support the <code>audio</code> element.</p>
  </audio>
Run Code Online (Sandbox Code Playgroud)

我可以得到它ready

  ready () {
    this.player = document.getElementById('player')
  },
Run Code Online (Sandbox Code Playgroud)

我可以控制它 methods

play: function () {
  this.player.play()
},
Run Code Online (Sandbox Code Playgroud)

但是当我{{ currentTime }}在模板中使用时

计算表达式“ currentTime”时出错。

未捕获的TypeError:无法读取null的属性“ currentTime”

javascript audio html5 vue.js

2
推荐指数
2
解决办法
7487
查看次数

标签 统计

audio ×1

html5 ×1

javascript ×1

vue.js ×1