-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Description
Vue version
latest
Link to minimal reproduction
Steps to reproduce
Make a Directive (referred to as "Test Directive 1") with mounted hook that sets innerText of element to a unique value different that Test Directive 2.
Then make another Directive (referred to as "Test Directive 2") with simmilar mounted hook that sets innerText of element to another value.
Make a toggle ref, and a button to change the toggle, then make a v-if where the key is the number 1 with Test Directive 1, and v-else with no key, with Test Directive 2.
Then click the toggle button, and you'll see that innerText is not changed, hence the other Test Directive's mounted hook was not called.
What is expected?
What should be expected is that the v-else is a diffrent element meaning directives should run mounted hook again, but instead it does nothing.
What is actually happening?
Keys:
The Vue Compiler generates keys for v-if/v-else, but it does not check for conflicts, in this case we set key to Number 1, which the Vue Compiler uses for v-else.
Directives:
Vue runs invokeDirectiveHook for mounted hook when the element is mounted, not when the Directive is "mounted".
System Info
Any additional comments?
You can make keys generated by vue compiler symbols, or check for conflicts (might be more difficult to do at compile time tho especially with dynamic keys).
You can run mounted hook and and destroyed hook when the directive itself is added or removed (and keeping of course the current when element is mounted/unmounted.)