this is the json response i get in my dom
{ "resource": "services", "status": "success", "data": [ { "service_id": "0001", "service_name": "Buy Airtime", "service_type": "airtime" }, ] }
this is how my template
<li v-for="service in responseObject">
{{ service }}
</li>
this is my script tag
<script>
import axios from "axios";
export default {
data() {
return {
status: false,
responseObject: {}
};
},
async mounted() {
try {
let response = await axios.get("http://localhost:4000/api/blogs");
this.responseObject = response.data;
} catch (e) {
console.log(e);
}
}
};
</script>
how can i display
service_id and service_name in my template
i’ve tried
service.data[0].service_name
but i’m not getting any response
4
Answers
Just do
since
service
represent one item of the arrayYou can access the child "data" array by adding dot notation to your v-for statement ("responseObject.data")-
Codepen – https://codepen.io/bsod_/pen/wvYwBrj
You can try printing response.data Confirm if the correct data has been obtained
this what you are missing
modify your code
then in your template
you should see an output