1

I have a table and the row has to be clickable. This click should fire a function in the parent component. The example below actually works, but it gets messy. Normally I would wrap the row in a <router-link> tag, but one cell has a value that may not be clicked.

<td
  @click.prevent="(!day.submitted || day.rejected ) ? $emit('update', day) : ''" 
  onMouseOver="this.style.cursor='pointer'"
  class="py-0 w-1/4">

Is it possible to write this shorter? I already tried to use a custom directive, but I can't get it to work.

<td clickMe>{{ day.hours }}</td>

Something like this would be ideal, any ideas on how I can achieve this?

1

1 Answer 1

3

The easiest way is to use a custom css class class="pointer":

In <template>:

<td
  @click.prevent="(!day.submitted || day.rejected ) ? $emit('update', day) : ''" 
  class="py-0 w-1/4 pointer">

in <style> or <style scoped>:

<style>
.pointer {
  cursor: pointer;
}
</style>
Sign up to request clarification or add additional context in comments.

1 Comment

Better would be to add a meaningful class name which describes what the rows represent rather than one that describes how they look/behave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.