Created
May 7, 2019 14:20
-
-
Save RodrigoFraga/49cf179c3fdf5c6f775450b613137bd3 to your computer and use it in GitHub Desktop.
Vuetify with v-money
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 class="v-input v-text-field v-input--is-label-active v-input--is-dirty theme--light" :class="{'error--text': errorMessages.length, 'v-input--is-focused': input_active}"> | |
<div class="v-input__control"> | |
<div class="v-input__slot"> | |
<div class="v-text-field__slot"> | |
<label aria-hidden="true" style="left: 0px; right: auto; position: absolute;" | |
class="v-label theme--light v-label--active" :class="{'error--text': errorMessages.length}">{{label}}</label> | |
<money | |
v-model="money" | |
v-bind="configCurrency" | |
@input="$emit('input', money)" @focus.native="onFocus($event)" @blur.native="onBlur" | |
></money> | |
</div> | |
</div> | |
<div class="v-text-field__details"> | |
<div class="v-messages theme--light error--text"> | |
<div class="v-messages__wrapper"> | |
<div class="v-messages__message" v-if="errorMessages.length">{{errorMessages[0]}}</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'AppMoney', | |
props: { | |
label: {type: String, required: true}, | |
value: {required:true}, | |
errorMessages: {type: Array, default: () => []}, | |
options: {type:Object, default: () => ({})} | |
}, | |
data() { | |
return { | |
configCurrency: {decimal: ',', thousands: '.', prefix: 'R$ ', precision: 2, masked: false, ...this.options}, | |
money: 0, | |
input_active: false | |
} | |
}, | |
methods: { | |
onFocus(event) { | |
event.target.select(); | |
this.input_active = true; | |
}, | |
onBlur(event) { | |
this.input_active = false; | |
} | |
}, | |
watch:{ | |
value(val){ | |
this.money = parseFloat(val) + 0.001; | |
} | |
}, | |
} | |
</script> | |
<style scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment