Utilizing data obtained from an API using V-TAB in vuetify, fetched through axios in vue js

I am currently working on promoting a V-TAB feature, where each tab will display specific data as shown in the following images: https://i.sstatic.net/vhtsG.jpg https://i.sstatic.net/CZxbt.jpg I intend to populate the TAB PROFILE with attributes like firstName, lastName, email, phone, and more. Additionally, I plan to include services array data in the TAB SERVICES, all extracted from the JSON object below:

[
        {
            "id": 1,
            "firstName": "Ana",
            "lastName": "Lucia",
            "phone": "(11)99989-8989",
            "mobilePhone": "(11)99989-8989",
            "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="14757a7d7a7c75547379757d783a777b79">[email protected]</a>",
            "gender": {
                "name": "feminino"
            },
            "status": {
                "name": "inativo"
            },
            "services": [
                {
                    "name": "progressiva"
                },
                {
                    "name": "Manicure"
                }
            ]
        }
    ]
    

I am uncertain about how to implement this functionality using the v-tab component within the provided Vuetify code snippet:

<template>
    <v-container grid-list-xl fluid > ;
      <v-layout row wrap> ;
        <v-flex sm12> ;
          <v-row
            class="mb-6"
            justify="center"
          > ;
            <v-col sm="10"& gt ;
              <v-card> ;
                <v-tabs
                  v-model="tab"
                  fixed-tabs
                  background-color="pink lighten-1"
                  dark
                > ;
                  <v-tab
                    v-for="item in items"
                    :key="item.tab"
                  > ;
                    {{ item.tab }}
                  </v-tab> ;
                </v-tabs> ;

                <v-tabs-items v-model="tab"& gt ;
                  <v-tab-item
                    v-for="item in items"
                    :key="item.tab"
                  > ;
                    <v-row justify="center"& gt ;
                      <v-col sm="6"& gt ;
                        <v-card flat> ;
                          <v-card-text class="body-1"& gt ;{{ item.content }}& lt ;/v-card-text> ;
                        </v-card> ;
                      </v-col> ;
                    </v-row> ;
                  </v-tab-item> ;
                </v-tabs-items> ;
              </v-card> ;
            </v-col> ;
          </v-row> ;

        </v-flex> ;
      </v-layout> ;
    </v-container> ;
    & lt ;/template> ;


    <script>
    import axios from 'axios '
    export default {
        data () {
          return {
            tab: null,
            employee: [],
            items: [
              { tab: 'Comissões', content: 'Here goes COMMISSIONS data' },
              { tab: 'Desempenho', content: 'Here goes PERFORMANCE data' },
              { tab: 'Serviços', content: 'Here goes SERVICES data' },
              { tab: 'Agendamentos', content: 'Here goes APPOINTMENT data' },
              { tab: 'Histórico', content: 'Here goes HISTORY data' },
              { tab: 'Perfil', content: 'Here goes PROFILE data' },

            ],
          }
        },

        created () {
          this.initialize()
        },

        methods: {
          initialize () {
              axios.get('http://192.168.26.130:3000/employee/1 ') 
                .then(response =& gt; {
                console.log(response.data);
              });
          },
        },
      }
    </script>
    

I am facing challenges in correctly displaying the contents in the respective tabs. For example, including the following content snippet:

{ tab: 'Perfil ', content: 'employee '},
    

When added, it simply renders the word "employee", while my intention is to render the actual content of the 'employee' object. Similarly, I aim to populate other tabs accordingly. Even after modifying the html snippet as follows:

<v-card-text class="body-1"& gt ;{{ employee}}< ;/v-card-text> ;
    

The entire 'employee' object gets rendered without proper formatting across all tabs, similar to the scenario depicted in the image: https://i.sstatic.net/nU57L.jpg Any assistance or guidance on resolving this issue would be greatly appreciated.

Answer №1

        <script>
    import axios from 'axios'
      export default {
        data () {
          return {
            tab: null,
            employee: [],
            services: [],
            items: [
              { tab: 'Comissões', content: 'Aqui vai os dados de COMISSÕES' },
              { tab: 'Desempenho', content: 'Aqui vai os dados de DESEMPENHO' },
              { tab: 'Serviços', content: services },
              { tab: 'Agendamentos', content: 'Aqui vai os dados de AGENDAMENTO' },
              { tab: 'Histórico', content: 'Aqui vai os dados de HISTÓRICO' },
              { tab: 'Perfil', content: employee },

            ],
          }
        },

        created () {
          this.initialize()
        },

        methods: {
          initialize () {
              axios.get('http://192.168.26.130:3000/employee/1')          
                .then(response => {
                  console.log(response.data);
                  this.employee = response.data
                  this.services = this.employee.services
                  delete this.employee.services
              });
          },
        },
      }
    </script>

Ensure that you fetch the data as an object and not an array (if using mongoose, consider using findOne or findById)

Answer №2

It seems like your goal is to display unique content in each V-TAB and you are interested in showcasing JSON data for the V-TAB. I recommend referring to the Vuetify documentation for guidance on how to achieve this.

Check out this link for more information:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Best practice for connecting ng-model in ng-repeat

I have the following list: "List": { "lorem": 127, "ipson": 5.5, "dolor": 29, "sit": 19} Next, I am utilizing the ng-repeat code below to construct a table with input fields: <table> <tr ng-repeat="(item, weight in settings.list"> ...

"Troubleshooting: Issue with AngularJS ng-click Functionality Not Working on Re

Having trouble with the ng-click function in AngularJS when using the following HTML code: <tr ng-repeat="ai in alert_instances" ng-click="go('/alert_instance/{{ai.alert_instancne_id}}')"> <td>{{ai.name}}</td> <td>{{a ...

Tips for extracting data from a JSON file

I'm attempting to retrieve a list of music genres from my json file using PHP and JQuery ajax. Here is the format of my json file [ "12-bar blues", "2 tone", "2-step garage", "4-beat", "50s progression", "a cappella", "accordion", " ...

Achieving form validation in Angular through external data binding techniques

I am facing a challenge with my Angular 4 form as the data is being tracked in an injected service, which is necessary for the project. For each input, the code looks like this... <input name="..." [ngModel]='getVal(...)' (ngModelChange)=&ap ...

What is the best way to use jQuery to fill a dropdown menu with options from a JSON object?

Looking to populate a dropdown box #dropdown with values from a json object stored in a JavaScript string variable. How can I access each element as value/label pairs and insert them into the dropdown? The structure of the json string is as follows: [{"n ...

Creating a versatile React component library with bundled prop types

Currently, I am having some fun creating a React components library using Typescript and Storybook. My initial Button component seems to be functioning well. In a separate CRA demo application, I am testing out this library as an end user. However, I am f ...

Is VueAxios compatible with the Vue composition API?

Currently, I find myself in main.js where I am importing vue-axios Main.js import { createApp } from 'vue'; import axios from 'axios'; import VueAxios from 'vue-axios'; import App from './App.vue'; const app = crea ...

Implementing Role-Based Access Control (RBAC) with an express backend and passport authentication

I am currently in search of an RBAC package or a demonstration using middleware on Express router. My goal is to establish different roles such as admin, manager, and user during registration, and then verify these roles with each backend request. Althou ...

Utilize Multer to seamlessly upload a file in Node.js and Angular environment

I am facing a challenge while trying to upload a file to my SQLite3 database. Every time I attempt the code below, I encounter a 500 error, although there is no indication of such an error in my request. I also experimented with using formData, but unfortu ...

Node.js: Steps for receiving an ArrayBuffer in a $http request

I made a request using $http.post from Angular.js to Node.js, expecting to receive an ArrayBuffer. Here is the code snippet: $http.post('/api/scholarships/load/uploaded-files', Global.user, {responseType:'arraybuffer'}).success(functi ...

When attempting to process a JSON string with JQuery's parseJSON() method, no response or error is returned

I've spent some time searching on various forums to find a solution to my problem, but it seems that no one else has encountered it. I am retrieving a JSON string from a field in my MySQL table, which is in the following format: {"width":"10", "heig ...

Ways to divide elements of an array into pairs

I am working with a javascript array containing values [A,B,C,D,E.....] that needs to be split using the following syntax: [ [A, B], [C, D], [E, F] ] This splitting process should always result in pairs. I attempted to achieve this using a loop to retur ...

Ensure that the hover div remains open even after the mouse leaves, and only closes when clicked outside of the div window or on a

I have a jQuery script that controls the opening and closing of the "shopping_cart" div when hovering over the "shopping_button". $('#shopping_button, .shopping_cart').on('mouseenter',function(){ $(this).css('z-index',&apos ...

How to Utilize Raw HTML in GWT with the Power of Jquery/Javascript?

Below is the HTML code snippet: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function( ...

The issue in Vue JS arises when trying to access JSON key values from an object array using v-for

I am currently working on parsing a list of objects found within a JSON payload into a table utilizing Vue.js. My goal is to extract the keys from the initial object in the array and use them as headings for the table. While the code I have in place succe ...

Sending AJAX requests in Laravel can be done in a few simple steps. To

I'm attempting to build a form that can add content to my database and display it without having to refresh the page, using Laravel 4.2. However, I'm struggling to determine the exact steps to achieve this. Whenever I submit the form, I end up on ...

Is there a way to detect in the browser when headphones have been unplugged?

Is there an event to pause the video when the audio device changes, like if headphones get unplugged? I've looked into other questions, but they don't seem to be for browser. Detecting headphone status in C# Detecting when headphones are plugg ...

Adding the eval function to custom template tags in Vue CLI 3

Currently, I am utilizing a webpack-dev server for developing a Vue application (Vue CLI 3). Our organization employs a specialized templating language that bears resemblance to ASP.NET (where functions commence with <% and finish with %>, being eval ...

Tab buttons that switch between different sections with just a click

Forgive me if this seems like a simple coding issue, but I struggle with javascript and need some guidance... I have a setup where two buttons (blue and yellow) toggle between different content divs. On another part of the page, there are also two buttons ...

What is causing the data to be altered outside of the directive scope?

I am having trouble understanding why the data is changing outside the directive in the external div. I expected it to behave the same as in the controller because the external Div is not wrapped in a directive or controller. Therefore, it should remain un ...