'How to get context vnode in vue 3 directives
Сan't get context from directive
<template lang="pug">
div(class="form")
select(name="name" v-model="form.input" v-select="form.inputs")
option(v-for="(option, key) in data" :value="key")
| {{values[key].value}}
</template>
<script>
export default {
data() {
return {
data: []
}
},
directives: {
select: {
mounted: function(el, binding, vnode) {
console.log(vnode.context); // return undefined
}
}
}
}
</script>
vnode.context - return undefined
vnode.appContext - return null
Solution 1:[1]
<script>
export default {
data() {
return {
data: []
}
},
directives: {
select: {
mounted: function(el, binding) {
console.log(binding.instance);
}
}
}
}
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrew |
