vue 添加事件监听器的方法

494 阅读1分钟

html内元素

 <input type="file"  ref="document" id="document"  
 class="p-a" style="top:0;left:0;backgroud:red;width:80px;opacity: 0;cursor: pointer;"  />

vue生命周期

 mounted() {
      //添加事件监听器
      this.$refs.document.addEventListener("change", this.readFileInputEventAsArrayBuffer, true)
      console.log("添加事件监听器");
      },
   beforeDestroy(){
     //移除事件监听器
      this.$refs.document.removeEventListener("change", this.readFileInputEventAsArrayBuffer, true)
       console.log("移除事件监听器");
   } ,  

methods

readFileInputEventAsArrayBuffer(event){
log event}

另外关于事件监听可以参考这个 blog.csdn.net/sunhuaqiang…?