Skip to content

Instantly share code, notes, and snippets.

@Haerezis
Created June 21, 2023 14:35
Show Gist options
  • Save Haerezis/535ab1b9242921924fcb649a072f32fc to your computer and use it in GitHub Desktop.
Save Haerezis/535ab1b9242921924fcb649a072f32fc to your computer and use it in GitHub Desktop.
Custom Input or v-model proxy component
<template>
<label>
VModelProxy
<input type="text" v-model="localValue">
</label>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
const props = defineProps({
value: String
})
const emit = defineEmits(['input'])
const _localValue = ref(props.value)
const localValue = computed({
get: () => _localValue.value,
set: (newValue) => {
_localValue.value = newValue
emit("input", newValue)
}
})
watch(
() => props.value,
(newValue) => _localValue.value = newValue
)
</script>
@Haerezis
Copy link
Author

Haerezis commented Jul 4, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment