Skip to content

Instantly share code, notes, and snippets.

@Haerezis
Last active July 4, 2023 09:00
Show Gist options
  • Save Haerezis/e1737f113ee86fe109c39ff113fd4656 to your computer and use it in GitHub Desktop.
Save Haerezis/e1737f113ee86fe109c39ff113fd4656 to your computer and use it in GitHub Desktop.
VModelProxy.vue (vuejs 3)
<template>
<label>
VModelProxy
<input type="text" v-model="localValue">
</label>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
const props = defineProps({
modelValue: String
})
const emit = defineEmits(['update:modelValue'])
const _localValue = ref(props.modelValue)
const localValue = computed({
get: () => _localValue.value,
set: (newValue) => {
_localValue.value = newValue
emit("update:modelValue", newValue)
}
})
watch(
() => props.modelValue,
(newValue) => _localValue.value = newValue
)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment