Custom v-if / v-if source code #9452
-
Hello community, I want to ask, if someone knows the source code of v-if directive. I tried to search for it, but I dont know, Im blind or something, because I was not able to find it. Im asking this, because I want to implement my own custom directive, which works exactly the same as v-if directive, but with custom logic (checking user, checking permissions etc). I know, I can use something like this But this looks more clearly and its shorter Do you know how to implement this? Im using something similar in angular (I dont like angular), but I was wondering, if its possible to use it also in Vue 3. Thank you. Have a nice weekend |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You don't find it because control flow directives like v-if and v-for are not normal directives with runtime code - they are handled during template copmilation by the compiler and replaced with actual Javascript code. That is to say: If you want to write a directive that works similar to v-if, you would have to write a vite-plugin or something that extends the Vue compiler to enable that. You can't really implement v-if/else logic with a runtime custom directive. |
Beta Was this translation helpful? Give feedback.
-
I would like to recommend |
Beta Was this translation helpful? Give feedback.
You don't find it because control flow directives like v-if and v-for are not normal directives with runtime code - they are handled during template copmilation by the compiler and replaced with actual Javascript code.
That is to say: If you want to write a directive that works similar to v-if, you would have to write a vite-plugin or something that extends the Vue compiler to enable that. You can't really implement v-if/else logic with a runtime custom directive.