vuejs-challenges icon indicating copy to clipboard operation
vuejs-challenges copied to clipboard

26 - 实现简易版`v-model`指令

Open GazzyLifeSense opened this issue 1 year ago • 0 comments

const VOhModel = {
	mounted(el) {
    // value发生改变后,同步到输入框
    watchEffect(()=>{
      el.value = value.value;
    })
    // 输入框输入后,同步到value
    el.onInput = (e) => {
      value.value = e.target.value;
    } 
    el.addEventListener('input', el.onInput);
  },
  beforeUnmount(el) {
    el.removeEventListener('input', el.onInput);
  }
}

GazzyLifeSense avatar Jan 28 '24 11:01 GazzyLifeSense