mirror of
https://github.com/tenrok/maska.git
synced 2026-06-17 19:21:21 +03:00
fix(vue): use defineExpose to set argument value
This commit is contained in:
+6
-6
@@ -5,16 +5,16 @@ type MaskaDirective = Directive<HTMLElement, MaskInputOptions | undefined>
|
||||
|
||||
const masks = new WeakMap<HTMLInputElement, MaskInput>()
|
||||
|
||||
// hacky way to update binding.arg without using defineExposed
|
||||
const setArg = (binding: DirectiveBinding, value: string | boolean): void => {
|
||||
if (binding.arg == null || (binding.instance == null)) return
|
||||
|
||||
const inst = binding.instance as any
|
||||
const isComposition = 'setup' in binding.instance.$.type
|
||||
|
||||
if (binding.arg in inst) {
|
||||
inst[binding.arg] = value // options api
|
||||
} else if (inst.$?.setupState != null && binding.arg in inst.$.setupState) {
|
||||
inst.$.setupState[binding.arg] = value // composition api
|
||||
if (binding.arg in binding.instance) {
|
||||
// @ts-expect-error
|
||||
binding.instance[binding.arg] = value
|
||||
} else if (isComposition) {
|
||||
console.warn('Maska: please expose `%s` using defineExpose', binding.arg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user