Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue render element with directive

Tags:

vue.js

vuejs2

I'm trying to render this directive using Render Function

<h2 v-tooltip.top="{ content: 'You have new messages.', classes: 'tooltip-info', offset: 15 }">
            some text
</h2>

Using this code inside function

return createElement('h2', {
                    directives: [
                        {
                            name: 'v-tooltip',
                            value: {
                                content: field.tooltip.content ? field.tooltip.content : field.tooltip,
                                classes: field.tooltip.class ? field.tooltip.class : 'tooltip-info',
                                offset: 15,
                            },
                            arg: 'top',
                        },
                    ],
                }, [field.title]);

but i get this error: [Vue warn]: Failed to resolve directive: v-tooltip

Am i missing something, field is object which might have content or class prop. So i set them if it has or go to default in the else.

v-tooltip is this directive https://github.com/Akryum/v-tooltip

like image 973
Georgi Antonov Avatar asked May 10 '26 19:05

Georgi Antonov


1 Answers

As I mentioned in the comments, v-tooltip should be changed to tooltip.

When defining a directive in vuejs, the name does not need the v- prefix: example:

Vue.directive('focus', {
  inserted: function (el) {
    el.focus()
  }
})

the above directive can be then called as:

<input v-focus>

source

like image 131
samayo Avatar answered May 13 '26 11:05

samayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!