Last active
March 25, 2024 08:32
-
-
Save Kcko/7663576d561087ab180ef8baab3b3472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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