After receiving JSON data from the server:
[
{"id":"2","name":"Peter","age":"24"},
{"id":"4","name":"Lucy","age":"18"},
]
I am trying to use it with the v-for
directive, but I'm having trouble getting it to work.
Here is my export default code:
data () {
return {
info: {}
}
},
mounted () {
axios
.get('http://localhost:4000/fetch.php/')
.then(response => (this.info = response.data))
},
When I display the output of info using {{ info }}
, it works well.
However, I need to use the v-for
directive to display only the names.
<p v-if="info.name">{{ info.name }}</p>
Unfortunately, this is not working as expected. The only thing that seems to work is {{ info[0].name }}
.