So I'd like to programmatically add an event, e.g. @click depending if on another variable. I can't really use a ref to do something like this.$refs.example.addEventListner("click", someFunction) because I'm doing it for a v-for
I've tried doing something like @click="clickable ? clicked : null" but the function isn't bound even when clickable is true
<template>
<div id="app">
<div class="main" @click="clickable ? clicked : null">
</div>
</div>
</template>
<script>
import HelloWorld from "./components/HelloWorld";
export default {
name: "App",
data() {
return {
clickable: false
};
},
methods: {
clicked() {
console.log("clicked");
}
},
components: {
HelloWorld
}
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.main {
background-color: yellow;
height: 200px;
width: 400px;
}
</style>