hjortur17
2 months ago
1249
12
Vue

Vue v-for

Posted 2 months ago by hjortur17

Hi, is it possible to only get one instance from Array? For example I have an array that looks like this:

[
    0: {id: 1, carMake: "Fólksbíll", description: "Alþrif & Bón", price: 14500, createdAt: null, …}
    1: {id: 2, carMake: "Fólksbíll", description: "Þrif að utan & Bón", price: 8900, createdAt: null, …}
    2: {id: 3, carMake: "Jepplingur", description: "Þrif að innan", price: 5900, createdAt: null, …}
    3: {id: 4, carMake: "Jepplingur", description: "Vélarþvottur", price: 4000, createdAt: null, …}
    4: {id: 3, carMake: "Jeppi", description: "Þrif að innan", price: 5900, createdAt: null, …}
    5: {id: 4, carMake: "Jeppi", description: "Vélarþvottur", price: 4000, createdAt: null, …}
]

And I'm creating a table and trying to use v-for to print out the carMake but I always get double the title, is it possible to make it only print out one time?

I'm doing it like this now:

<th  v-for="carMake in data" v-text="carMake.carMake"></th>
data() {
    return {
        data: []
    }
},

methods: {
    getPricesFromDatabase() {
        axios.get('/api/services/get')
        .then(response => {
            this.data = response.data;
        });
    }   
}

Please sign in or create an account to participate in this conversation.