I wanted to read the data from the database and display it in the app.
I’m calling it like this :
<h2 class="lowongan1" v-for="value in list_lowongan"> {{ value.title }}</h2>
<p class="descJob1" v-for="value in list_lowongan">{{ value.body }}</p>
The script
export default {
data() {
return {
'form': {
title: '',
body: '',
},
list_lowongan: []
};
},
mounted() {
console.log('on mounted');
axios.get('post/list').then((response) => {
console.log(response.data)
this.list_lowongan = response.data
}).catch((error) => {
console.log(error)
});
},
The problem is, when I call it like that, It displays all the title in the database and the body in the database tables.
How can I make it so that it only display 1 title for each h2 class ?
3
Answers
Use a wrapping div to hold your content and then loop over the div like so:
You have two for-loops independent of each other so they’ll stack by themselves
You just need one for-loop to display a list of where each
title
andbody
are togetherYou can form it this way:
As per your requirement, No need to use multiple
v-for
loops for same data iteration. Instead you can achieve that by applyingv-for
in a wrapper element and then prints the object values inside that wrapper element.Live Demo :