I've created a vue component to reuse thoughout my app but I'm struggling with one aspect the value being initially displayed in the input text field. It feels like there is something I'm misunderstanding about the the render cycle and how value binding works.
Here is the Vue component that I've made:
<template>
<div class="my-2">
<label for="name">{{ label }} </label>
<input
:id="id"
:name="name"
:class="{
input: true,
'input-error': errorMessage && errorMessage != '',
}"
:value="value"
v-on:input="action"
:type="type"
:required="!!required"
v-once
/>
<p v-show="errorMessage && errorMessage != ''" class="error-message">
{{ errorMessage }}
</p>
</div>
</template>
<script>
export default {
name: "BaseInput",
props: [
"defaultValue",
"label",
"type",
"id",
"name",
"errorMessage",
"required",
],
computed: {
value() {
console.log(this.defaultValue);
return this.defaultValue
},
},
methods: {
action(e) {
this.$emit("input", e.target.value);
},
},
};
</script>
and I reference it in my parent component as such:
<base-input label="Base Input 2" id="in2" name="name" v-model="value"></base-input> {{value}}
when the page loads the {{value}} displays value as expected, but the input does not actually display the text
@inputin the parent