Open Pacheco95 opened 3 years ago
In a more reusable way
// masked-input.vue
<template>
<InputMask class="ant-input" :value="value" :mask="mask" @input="change" />
</template>
<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'
import { Emit, Model, Prop } from 'vue-property-decorator'
import { TheMask } from 'vue-the-mask'
@Component({
components: {
InputMask: TheMask,
},
})
export default class MaskedInput extends Vue {
@Prop({ type: [String, Array], required: true })
readonly mask!: string | string[]
@Model('change', { type: String })
readonly value!: string
@Emit()
change(value: string) {
return value
}
}
</script>
I'm adding this example as an issue for those who wants to know how to integrate this awesome lib with ant design for vuejs (antd).
If you go to ant input docs you will find an example of a customized form control. If the link does not scroll to the correct doc section, all you just need to do is to search for "Customized Form Controls".
As you can see, to use antd with 3rd party libraries, there are somre requirements that should be follwed:
Here I'll show you how to create a masked input for brazilian phone input numbers and I'll also use class components and typescript but you can quickly convert the code to "pure" vuejs code. So, let's get our hands dirty!
First of all, you need to create an wrapper component to your custom input like this:
And use it in another component!
Here, antd will pass
initialValue
fromv-decorator
to ourBRLPhoneInput
component as aprop
and everything will work perfectly as expected! See demo below.Hope it hepls!