[Vuejs]-Changing v-data-table status when getting RestAPI using axios method

3👍

How to show the status:

  1. Status needs to be a part of item, or else the status is going to be the same for all items. So change <td>{{status}}</td> to <td>{{item.status}}</td>.
    And change { text: 'status', value: '' } to { text: "status", value: "status" }.
  2. this.items.id is not valid since this.items is an array.
  3. Also when you check if a value is equal a string you should use ===, which means equal value and equal type. See more about comparisons here: https://www.w3schools.com/js/js_comparisons.asp

What I would do is to add the status while mapping the items:

this.items = response.data.map(item => {
      const newStatus =
        item.id === '1' || item.id === '3' ? 'supercustomer' : '';
      return {
        id: item.id,
        email: item.email,
        name: item.name,
        status: newStatus
      };
 });
👤milmal

Leave a comment