We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v-model
`<script setup lang='ts'> import { ref, watchEffect } from "vue" /**
interface DirectiveEl extends HTMLInputElement { value: string vueInputListener: any }
const VOhModel = { mounted(el: DirectiveEl, binding: DirectiveBinding) { el.value = binding.value; console.log('执行mounted') const handleInput = (e: Event) => { value.value = (e.target as DirectiveEl).value }; el.addEventListener('input', handleInput, false); // 存储监听器引用以便稍后可以移除 el.vueInputListener = handleInput; }, updated(el: DirectiveEl, binding: DirectiveBinding) { console.log('执行updated') el.value = binding.value; }, unmounted(el: DirectiveEl) { if (el.vueInputListener) { el.removeEventListener('input', el.vueInputListener, false); } } };
const value = ref("Hello Vue.js") const setValue = () => { value.value = 'tang' }
{{ value }}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
`<script setup lang='ts'>
import { ref, watchEffect } from "vue"
/**
*/
interface DirectiveBinding {
value: string
}
interface DirectiveEl extends HTMLInputElement {
value: string
vueInputListener: any
}
const VOhModel = {
mounted(el: DirectiveEl, binding: DirectiveBinding) {
el.value = binding.value;
console.log('执行mounted')
const handleInput = (e: Event) => {
value.value = (e.target as DirectiveEl).value
};
el.addEventListener('input', handleInput, false);
// 存储监听器引用以便稍后可以移除
el.vueInputListener = handleInput;
},
updated(el: DirectiveEl, binding: DirectiveBinding) {
console.log('执行updated')
el.value = binding.value;
},
unmounted(el: DirectiveEl) {
if (el.vueInputListener) {
el.removeEventListener('input', el.vueInputListener, false);
}
}
};
const value = ref("Hello Vue.js")
</script>const setValue = () => {
value.value = 'tang'
}
{{ value }}
The text was updated successfully, but these errors were encountered: