TypeError: Cannot read property 'forEach' of undefined

Getting Error: TypeError: Cannot read property ‘forEach’ of undefined,
TypeError:Cannot read property ‘undefined’ of undefined
On sorting table value

computed: {
filteredData: function() {
  var sortKey = this.sortKey
  var filterKey = this.filterKey && this.filterKey.toLowerCase()
  var order = this.sortOrders[sortKey] || 1
  var data = this.data
  if (filterKey) {
    data = data.filter(function(row) {
      return Object.keys(row).some(function(key) {
        return (
          String(row[key])
            .toLowerCase()
            .indexOf(filterKey) > -1
        )
      })
    })
  }
  if (sortKey) {
    data = data.slice().sort(function(a, b) {
      a = a[sortKey]
      b = b[sortKey]
      return (a === b ? 0 : a > b ? 1 : -1) * order
    })
  }
  return data
},

},
methods: {
sortBy: function(key) {
this.sortKey = key
this.sortOrders[key] = this.sortOrders[key] * -1
},
},

<table
  :class="$style.dataTable">
  <thead :class="$style.tableHead">
    <tr>
      <th
        :class="[{ active: sortKey == key }, $style.tableColumn]">
        <input type="checkbox">
      </th>
      <th
        v-for="key in columns"
        :class="[{ active: sortKey == key }, $style.tableColumn]"
        :key="key.id"
        @click="sort ? sortBy(key) : ''">{{ key | capitalize }}
        <span :class="[sortOrders[key] > 0 ? 'asc' : 'dsc', [$style.arrow]]"/>
      </th>
    </tr>
  </thead>
  <tbody :class="$style.tableBody">
    <tr
      v-for="entry in filteredData"
      :key="entry.id"
      :class="$style.tRow">
      <td>
        <slot name="action"/>
      </td>
      <td
        v-for="key in columns"
        :key="key.id"
        :class="[isNaN(entry[key]) ? '' : $style.numcell, $style.tableContent ]">{{ entry[key] }}</td>
    </tr>
  </tbody>
</table>

Calling component externally

<Table
  :data="gridData"
  :columns="gridColumns"
  :filter-key="searchQuery"
  :sort="true"/>

To avoid the error, you can test your value using a v-if statment before using it in a foreach loop e.g.

v-if="colums && columns.length"