0
How to build a Custom Directive that works like v-on
?
Briefly the directive needs to have the same functionality as the v-on:click
I tried things like:
//App.vue:
<h1 v-arthur:click="myfunction">Directives Exercise</h1>
//main.js:
Vue.directive('arthur', {
myfunction(){
alert('minha diretiva personalizada v-on funcionou!');
}
});
<script>
export default {
methods: {
myfunction();
}
}
</script>
But it wasn’t, because I don’t know how to do, it’s wrong to call a function within methods, but I’ve tried everything, someone can help me?
Man, that’s just not possible, like it’s out of character what you’re trying to do. Custom directives do not work that way and were not created to do so.
– LeAndrade
I’m taking a course at udemy and has some exercises... In one of them has the following activity " Build a Custom Directive that works as v-on (Listen to Events)"
– Arthur
Maybe I misunderstood but from what I understand, it is to make a directive that has the same functionality as v-on ........
– Arthur
Well, I don’t see how to do it, and if there is, it’s a scam. But if it’s done you can post the code as an answer if anyone has any similar questions.
– LeAndrade