Vuejs 2 $refs返回未定义



我正在尝试在加载页面时重新加载 html5 音频,因为它具有动态路径,但我似乎无法访问 $ref 属性,无论是在mounted还是watch这里是代码

<audio ref="player" controls>
<source v-bind:src="track">
Your browser does not support the audio element.
</audio>
watch:{
details : function(){
this.verdict = ''
this.track = '../../public/wavfile/' + this.details.file;
console.log(this.$refs)
}
},
mounted(){
console.log(this.$refs)
}

根据文档,您无法在初始渲染时访问引用。

试试这个

console.log(this.$refs['player'])

console.log(this.$refs.player)

最新更新