Input addEventListener on change not firing

前端 未结 2 1407
再見小時候
再見小時候 2021-01-26 05:59

I have a single input to upload a image.

html

2条回答
  •  春和景丽
    2021-01-26 06:50

    Change your event to this:

    this.imageInput.addEventListener("change", () => this.uploadImage());
    

    Or to this:

    this.imageInput.addEventListener("change", this.uploadImage.bind(this));
    

    What you are doing is calling uploadImage and passing the result of that to the listener. You want to pass the reference to the listener.

提交回复
热议问题