我正在使用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”