JS 代码如下:
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "progress", "volume", "progressbar"]
connect() {
if(!window.__audioEl) {
window.__audioEl = document.createElement("audio")
window.__audioEl.addEventListener("timeupdate", this.onTimeUpdate, true)
}
}
onTimeUpdate() {
// undefined
console.log(this.progressTarget)
}
}
在 onTimeUpdate
函数中无法访问 this.progressTarget
。刚学 Stimulus,感觉有点困惑。