0

I have a table called candidate_profiles with several columns inside of it. Even though a User can have only one profile, I'd like to know how to display the data using a v-for loop because I will need this in other pages of the application.

When I console.log(response) , I can see the data in the console, but it's not displaying. What am I missing?

CandidateProfileIndex.vue:

<template>
    <div>
        <table class="table">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>experience</th>
                    <th>skills</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(profile, index) in profiles" :key="index">
                    <td>{{profile.id}}</td>
                    <td>{{profile.experience}}</td>
                    <td>{{profile.skills}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script>
    import * as profileService from '../../services/candidate_profile_service.js';

    export default {
        name: "candidateProfileIndex",

        data() {
            return {
                profiles: [],
            };
        },

        mounted() {
            this.loadProfile();
        },

        methods: {
            loadProfile: async function() {
                try {
                    const response = await profileService.loadProfile();
                    console.log(response);
                    this.profiles = response.data.data;
                    console.log(this.profiles);
                } catch (error) {
                    this.$toast.error("Some error occurred, please refresh!");
                }
            }
        }
    }
</script>

candidate_profile_service.js:

import {http, httpFile} from './http_service';

export function createProfile(data) {
    return httpFile().post('candidate-profile', data);
}

export function loadProfile() {
    return http().get('/candidate-profile/create');
}

Below is a screenshot of the data in the console. enter image description here

1
  • 2
    Won't it be this.profiles = response.data? Commented Apr 13, 2020 at 21:16

2 Answers 2

1

Your loadProfile method has some issue. You need to access the response.data.

loadProfile: async function() {
  try {
    const response = await profileService.loadProfile();
    console.log(response);
    this.profiles = response.data;
    console.log(this.profiles);
  } catch (error) {
    this.$toast.error("Some error occurred, please refresh!");
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

try to call loadProfile on created vs mounted :

created() {
   this.loadProfile();
}

or add, before you assign the variable to this.profiles :

await this.$nextTick()

Comments

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.