-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vue directive #51
Comments
You can with v-if <button v-if=“$can(“delete”, post)”>delete</button> |
Could you please explain why do you want to add additional directive? |
Because of readability |
It was done as method because having this you can do much more. For example,
|
So, do you think it makes sense to create a separate directive? |
2- This is passing props to a component so is has to be done throw the props it self, which why i don't think it falls within the scope of my issue. I'm talking about showing/hiding/rendering a component on the page. 3- Yep, to pass arguments we must use an array but it is not so bad isn't ? In laravel we have blade directives |
Ok. I see your point. I suggest this interface for the directive:
|
for per field check:
Also it will be shipped as separate plugin, this will allow to shake out it if unused. Frankly speaking, I prefer |
Nice |
ok, lets wait some time to see whether there are other people who wants such directive. |
This would be an excellent addition |
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 <div v-show=“$can(‘read’, ‘User’)”>... This kind of stuff works very nice with provided |
@shadoWalker89, it'd be awesome if you could provide a PR for this directive with tests. I use jest for testing |
You can start from simple directive which accepts array and later add more readable version if you need it |
@stalniy i'm sorry but i'm already using another package. |
Could you please share why you decided to go with another solution? Just want to understand and make CASL to be better :) |
Well, the main reason is that i looked up packages with the vue directive. Good luck with your package. |
An interesting article https://codeburst.io/reusable-vue-directives-v-can-753bf54e563f , probably will take some design suggested there :) |
After some investigation I found that it's possible to implement directive only with hacks which in future versions of Vue may not be supported. Taking a look at
That means if I implement directive with the same hack as in So, the best what I can do here is to provide a custom component |
keep track on progress in #63 |
Hi,
It would be really nice if we could do something like
Update:
Requirements:
Vue
plugin (e.g.,AbilityDirectives
)v-can
v-if
(i.e., remove/insert DOM nodes when condition changes)v-can="[action, subject, field]"
(e.g.,v-can="['read', post, 'title']"
)v-can.action.field.of="subject"
,.of
is optional, just for readability (e.g.,v-can.read.title.of="post"
,v-can.read="post"
)v-can.action.field.of.subject
,.of
is optional, just for readability (e.g.,v-can.read.title.of.Post
,v-can.read.Post
)The text was updated successfully, but these errors were encountered: