I'm creating a re-usable component for input fields where I can define them easier in one component tag with props. However, I want to make it versatile as to be able to use it as text, date, password, number etc. By a conditional prop. But I'm having trouble getting that prop to bind
Here is my input field component
<template>
<div class="uk-margin">
<label class="uk-form-label" for="trackid">{{label}}</label>
<div class="uk-form-controls">
<input v-if="number" class="uk-input" type="number" v-model="defaultvalue" />
<input v-else-if="date" class="uk-input" type="date" v-model="defaultvalue" />
<input v-else-if="email" class="uk-input" type="email" v-model="defaultvalue" />
<input v-else-if="password" class="uk-input" type="password" v-model="defaultvalue" />
<input v-else class="uk-input" type="text" v-model="defaultvalue" />
</div>
</div>
</template>
<script>
export default {
name: "input-text-field",
props: {
label: {
type: String
},
defaultvalue: {
type: String
},
type: {
type: String
},
number: {
type: Number
},
date: {
type: Object
},
email: {
type: String
},
password: {
type: String
}
},
data() {
return {
value: ""
};
}
};
</script>
And I'm calling like this or would like to use them like this
<InputField label="User Name" :defaultvalue="myName" />
<InputField label="User Email" email :defaultvalue="myEmail" />
<InputField label="User Password" password :defaultvalue="myPass" />
<InputField label="Tracking #" number :defaultvalue="trackingNumber" />
In my understanding of this, if I call password, it should obfuscate the value as it would render the type="password" given the conditional statement. No? What am I doing wrong
*P.S. the defaultvalue would be stored and used as a state. That part works. Right now, I am not getting console errors, but the component renders as a text regardless.