One of the challenges I'm facing is dealing with a custom attribute called my-custom-attribute
. This attribute contains the ID for the element that needs to have the attribute added or removed based on a boolean value.
Although I've implemented a solution in JavaScript that works well, I'm curious if there's a way to achieve this using Vue.js directives instead?
<div my-custom-attribute="my_element">
...
</div>
Here is the current JavaScript implementation:
const el = document.getElementById("some_id");
if(my_bool) {
el.setAttribute("my-custom-attribute", "#my-element");
} else {
el.removeAttribute("my-custom-attribute")
}