Add vue directive
See original GitHub issueHi,
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:
- Created 5 years ago
- Comments:20 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another thoughts on this topic:
Sometimes you may want to add css class based on user permissions:
Or use
v-show
instead ofv-if
This kind of stuff works very nice with provided
$can
method but not withv-can
ok, lets wait some time to see whether there are other people who wants such directive.