Complete the code to register a simple custom directive in Vue.
app.directive('focus', { mounted(el) { el.[1]() } })
The focus method sets keyboard focus on the element, which is the common use case for a focus directive.
Complete the code to use the custom directive in a template.
<input type="text" v-[1] />
The directive is used with v-focus to apply the custom focus behavior.
Fix the error in the directive definition to correctly access the element.
app.directive('highlight', { mounted([1]) { el.style.backgroundColor = 'yellow' } })
The first argument to the mounted hook is the element, commonly named el.
Fill both blanks to create a directive that changes text color based on a binding value.
app.directive('color', { mounted(el, [1]) { el.style.color = [1].[2] } })
The second argument is the binding object, and its value property holds the passed value.
Fill all three blanks to create a directive that updates element text on value change.
app.directive('text-update', { mounted(el, [1]) { el.textContent = [2] }, updated(el, [3]) { el.textContent = binding.value } })
The directive uses the binding object to access the value in both hooks. The updated hook also receives the binding as the second argument.