Answer the question
In order to leave comments, you need to log in
How to create a directive on VUE?
Hello.
Guys, tell me how to make a directive out of this ?
To make it look something like this
<div v-clipboard="someData">Copy button</div>
Answer the question
In order to leave comments, you need to log in
how to make a directive out of this ?
Note: This method is obsolete and should not be used. In particular, to interact with the clipboard, consider using the Clipboard API instead.
const clipboardDirective = (() => {
const values = new Map();
const onClick = e => navigator.clipboard.writeText(values.get(e.currentTarget));
return {
bind(el, binding) {
el.addEventListener('click', onClick);
values.set(el, binding.value);
},
update(el, binding) {
values.set(el, binding.value);
},
unbind(el) {
el.removeEventListener('click', onClick);
values.delete(el);
},
};
})();
Vue.directive('clipboard', clipboardDirective);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question