Guest User

Untitled

a guest
Jul 17th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <template>
  2. <v-text-field
  3. type="text"
  4. :value="formattedValue"
  5. @change="change"
  6. v-money="config"
  7. class="v-money"
  8. v-bind="$props"
  9. @blur="blur"
  10. ></v-text-field>
  11. </template>
  12.  
  13. <script>
  14.  
  15. import mask from '../../plugins/mask'
  16.  
  17. export default {
  18. name: 'VuetifyMask',
  19. inheritAttrs: true,
  20. props: {
  21. value: {
  22. required: true,
  23. type: [Number, String],
  24. default: 0
  25. },
  26. label: {
  27. type: String,
  28. default: ''
  29. },
  30. disabled: {
  31. type: Boolean,
  32. default: false
  33. },
  34. blur: {
  35. type: Function,
  36. default () {
  37. return null
  38. }
  39. }
  40. },
  41. data () {
  42. return {
  43. formattedValue: '',
  44. config: {
  45. decimal: ',',
  46. thousands: '.',
  47. prefix: ' ',
  48. suffix: '',
  49. precision: 2,
  50. masked: false
  51. }
  52. }
  53. },
  54. watch: {
  55. value: {
  56. immediate: true,
  57. handler (newValue, oldValue) {
  58. let formatted = mask.format(newValue)
  59. if (formatted !== this.formattedValue) {
  60. this.formattedValue = formatted
  61. }
  62. }
  63. }
  64. },
  65. methods: {
  66. change (evt) {
  67. this.$emit('input', mask.unformat(evt, 2))
  68. }
  69. }
  70. }
  71. </script>
Add Comment
Please, Sign In to add comment