Hide a button generated from v-for in a table in VueJS

  Kiến thức lập trình

I want to hide a button from a table. In the component there is a v-for looping in a table. In my response the button display two states (Cancel and Retake Snapshot buttons). I want to set a rule to only hide the Retake Snapshot button.

Here is a breakdown of my code

  1. Component holding the text of the button called clickableText
  <div class="clickable-text" @click="() => !disabled && onClick()">
    <div :class="className">{{ text }}</div>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
export default class ClickableText extends Vue {
  @Prop({ default: true }) text: string;
  @Prop({ default: true }) clickable: boolean;
  @Prop({ default: () => {} }) onClick: () => void;

  get className() {
    return {
      disabled: this.disabled,
      clickable: this.clickable && !this.disabled,
  1. ClickableText is called here in a component called ClickableTexts
  <div v-for="(item, id) in items" :key="id">
    <ClickableText v-bind="item" />

<script lang="ts">
import ClickableText from './ClickableText.vue';
export default class ClickableTexts extends Vue {
  @Prop() items: {
    text: string;
    disabled: boolean;
    classes: string;
    clickable: boolean;
    loading?: boolean;
    onClick: () => void;
  1. ClickableTexts is now called in a component called AppTable
<table class="table__wrapper">
      <thead class="table__headers mb-4">
          <th v-for="header in headers" :key="header.value" class="" :class="{ clickable: header.sortable }">
            <div class="d-flex align-center" @click="headerClicked(header)">
              {{ header.text }}
      <tbody class="table__items">
        <tr v-for="(item, n) in items" :key="n" data-qa="row" :id="item.id ? item.id.value : n" class="table__row">
          <td v-for="header in headers" :key="header.value" :data-qa="header.value">
            <div :class="itemClass(item, header)" @click="itemClicked(item, header)">
              <div v-if="item[header.value] && item[header.value].value">{{ item[header.value].value }}</div>
              <div v-else>
                <component :is="item[header.value].component" v-bind="item[header.value].props" :disabled="isLastOrSingleItem(n)" v-show="hasValidateGowker" />

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import { TableHeader, TableItem, TablePagination, AppTableItemClick } from './interfaces';

export default class AppTable extends Vue {
  @Prop() headers: TableHeader[];
  @Prop() items: TableItem[];
@Prop({ default: false }) hasValidateGowker: boolean;

  isLastOrSingleItem(index: number): boolean {
    return index === this.items.length - 1 || this.items.length === 1;

  itemClicked(item: TableItem, header: TableHeader): AppTableItemClick | undefined {
    const headerName = header.value;
    if (item[headerName]?.clickable) {
      const returnValue = { item, id: headerName };
      this.$emit('itemClicked', returnValue);
      return returnValue;

<component :is="item[header.value].component" v-bind="item[header.value].props" :disabled="isLastOrSingleItem(n)" v-show="hasValidateGowker" />

AND THE RESPONSE IS AS BELOW if I do {{item[header.value].props}}
{ "items": [ { "classes": "action-text ", "disabled": false, "text": "Cancel", "clickable": true, "show": true }, { "classes": "action-text", "disabled": false, "loading": false, "text": "Retake Snapshot", "clickable": true, "show": true } ] }

  1. Finally AppTable is called in this component
   v-if="hasSnapshots && !loadingSnapshots"

<script lang="ts">
export default class SnapshotController extends Vue {
  get hasValidateGowker() {
    return modules.user.hasPermission(UserPermissions.ValidateGowker);

hasValidateGowker() hides both buttons unfortunately.