How to tell which directive is which in vnode.dirs
?
#7439
Unanswered
LeaVerou
asked this question in
Help/Questions
Replies: 2 comments 5 replies
-
mb too late provide symbols with your directive to detect it. const RippleDirectiveSymbol = Symbol('RippleDirective')
return {
_directive: RippleDirectiveSymbol,
mounted,
unmounted,
updated,
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
to detect import { capitalize, getCurrentInstance } from 'vue'
/**
* Check instance for binds to v-model
* @param props
* @param {string} prop prop name
* @return {boolean}
*/
export function isVModel(props: any, prop: string = 'modelValue') {
const vm = getCurrentInstance()
if (!vm)
throw new Error ('isVModel must be called from the setup or lifecycle hook methods.')
if (props[prop] === undefined || !vm.vnode.props)
return false
return !!(
vm.vnode.props[`onUpdate:${prop}`] ||
vm.vnode.props[`onUpdate:model${capitalize(prop)}`]
)
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m writing a custom directive that needs to read

v-model
. I’ve discovered thatvnode
includes adirs
array with all (?) directives set on the element, however it seems impossible to tell which one is which, e.g. vModel looks like this:Right now I'm working around this by requiring that
v-model
is the first directive specified on elements using my custom directive but that's quite suboptimal. Is there any way to tell? Perhaps some way to obtain a reference to thev-model
directive object to compare against?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions