Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active March 25, 2024 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/7663576d561087ab180ef8baab3b3472 to your computer and use it in GitHub Desktop.
Save Kcko/7663576d561087ab180ef8baab3b3472 to your computer and use it in GitHub Desktop.
<template>
<div id="app">
Data z rodiče: {{ msg }}
<hr />
<Formik v-model="msg" />
</div>
</template>
<script>
import Formik from './components/Formik.vue';
export default {
name: 'App',
components: {
Formik,
},
data() {
return {
msg: 'pica2',
};
},
};
</script>
<template>
<!-- 1 zpusob -->
<input
type="text"
:value="modelValue"
@input="$emit('update:modelValue', $event.target.value)"
/>
<!-- 2 zpusob -->
<input v-model="inputak" />
<br />Data z child {{ modelValue }}
<Formik2 v-model="inputak" />
</template>
<script>
import Formik2 from './Formik2.vue';
export default {
name: 'Formik',
components: {
Formik2,
},
props: ['modelValue'],
data() {
return {};
},
computed: {
inputak: {
get() {
return this.modelValue;
},
set() {
this.$emit('update:modelValue', event.target.value);
},
/*
nebo
set(value) {
this.$emit('update:modelValue', value);
}
*/
},
},
};
</script>
<!-- 3 moznost pres watch -->
<template>
<input v-model="internalValue" />
</template>
<script>
export default {
name: 'Formik',
props: ['value'],
data() {
return {
internalValue: this.value
};
},
watch: {
value(newValue) {
this.internalValue = newValue;
},
internalValue(newInternalValue) {
this.$emit('update:value', newInternalValue);
}
}
};
</script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment