Skip to content
New issue

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

26 - 实现简易版v-model指令 #2788

Open
34benma opened this issue Aug 27, 2024 · 0 comments
Open

26 - 实现简易版v-model指令 #2788

34benma opened this issue Aug 27, 2024 · 0 comments

Comments

@34benma
Copy link

34benma commented Aug 27, 2024

// 你的答案
<script setup lang='ts'> import { ref, watchEffect } from "vue" /** * 实现以下自定义指令 * 在表单输入元素和数据间创建双向绑定 * */ const VOhModel = { mounted: (el, binding) => { watchEffect(() => { el.value = binding.value el.addEventListener('input', (e) => { el.value = e.target.value value.value = e.target.value }) }) } } const value = ref("Hello Vue.js") </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant