question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add vue directive

See original GitHub issue

Hi,

It would be really nice if we could do something like

<div v-can="deleteSomething">Delete something</div>

Update:

Requirements:

  • create a separate Vue plugin (e.g., AbilityDirectives)
  • this plugin should provide global directive v-can
  • directive should work similar to v-if (i.e., remove/insert DOM nodes when condition changes)
  • an array as argument to directive v-can="[action, subject, field]" (e.g., v-can="['read', post, 'title']")
  • arguments as directive arguments v-can.action.field.of="subject", .of is optional, just for readability (e.g., v-can.read.title.of="post", v-can.read="post")
  • arguments as directive arguments for class checks v-can.action.field.of.subject, .of is optional, just for readability (e.g., v-can.read.title.of.Post, v-can.read.Post)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
stalniycommented, Apr 17, 2018

Another thoughts on this topic:

Sometimes you may want to add css class based on user permissions:

<div :class=“{ my: $can(‘read’, ‘User’) }”>...

Or use v-show instead of v-if

<div v-show=“$can(‘read’, ‘User’)”>...

This kind of stuff works very nice with provided $can method but not with v-can

1reaction
stalniycommented, Apr 3, 2018

ok, lets wait some time to see whether there are other people who wants such directive.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Directives - Vue.js
Custom directives should only be used when the desired functionality can only be achieved via direct DOM manipulation. Prefer declarative templating using built ......
Read more >
How To Use Built-In and Custom Directives in Vue.js
In the Vue.js framework, you have the ability to create custom directives to suit the individual needs for your project. In this section,...
Read more >
How to create custom directives in Vue.js - Educative.io
We use the Vue.directive to register a custom directive globally. · We use the directives object to register a custom directive locally. It...
Read more >
A deep dive into custom Vue directives - LogRocket Blog
In this in-depth tutorial, learn how Vue directives can make your code cleaner and easier to read, and even give it an edge...
Read more >
Creating Your First Vue Custom Directive - with Vue 3 Updates
A Vue custom directive is, as you may guess, Vue's way of letting us build additional directives for our projects. They're a great...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found