mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-11-04 21:02:09 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			484 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			484 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * Bind event when mounted or activated
 | 
						|
 */
 | 
						|
import { on, off } from '../utils/dom/event';
 | 
						|
 | 
						|
export function BindEventMixin(handler) {
 | 
						|
  function bind() {
 | 
						|
    if (!this.binded) {
 | 
						|
      handler.call(this, on, true);
 | 
						|
      this.binded = true;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  function unbind() {
 | 
						|
    if (this.binded) {
 | 
						|
      handler.call(this, off, false);
 | 
						|
      this.binded = false;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  return {
 | 
						|
    mounted: bind,
 | 
						|
    activated: bind,
 | 
						|
    deactivated: unbind,
 | 
						|
    beforeDestroy: unbind
 | 
						|
  };
 | 
						|
}
 |