vuejs-challenges
vuejs-challenges copied to clipboard
26 - 实现简易版`v-model`指令
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);
}
}