Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass dynamic argument in vuejs custom directive

<template>
    <div>
        <img v-directive:dynamic_literal />
    </div>
</template>

E.g. dynamic_literal = 'ok' such that in custom directive:

Vue.directive('directive', {
    bind(el, binding) {  binding.arg  // should return 'ok'

How can I use dynamic_literal as a variable or a constant whose value should be assigned under data or prop.

I tried with v-directive:{{dynamic_literal}} and :v-directive="dynamic_literal" but no use.

Thanks in advance!

like image 541
Sukhwinder Avatar asked Jul 20 '17 18:07

Sukhwinder


1 Answers

working for me:

<div v-mydirective:[dynamicArg]="foo">

to access it with binding.arg

more info: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0003-dynamic-directive-arguments.md

like image 145
Christian Carrillo Avatar answered Oct 09 '22 22:10

Christian Carrillo