novice,
use axios to get json data
data.json section:
{
"contacts": [
{
"name":"",
"id":"pony",
"sex":1,
"region":" ",
"headerimg":"",
"momentsimg":"",
"personalnote":"",
},
{
"name":"",
"id":"AllenZhang",
"sex":1,
"region":" ",
"headerimg":"",
"momentsimg":"",
"personalnote":"",
},
{
"name":"",
"id":"rzf",
"sex":1,
"region":" ",
"headerimg":"",
"momentsimg":"",
"personalnote":"",
},
{
"name":"",
"id":"tyx",
"sex":0,
"region":" ",
"headerimg":"",
"momentsimg":"",
"personalnote":"",
},
],
"moments": [
],
"dialogue": [
]
}
js section:
<script type="text/javascript">
import axios from "axios"
export default{
data() {
return {
contacts: []
}},
created() {
axios.get("static/data.json").then(response =>
{
this.contacts = response.data.contacts;
//undifine
console.log(this.contacts)
});
},
}
</script>
the print result is undefined, but if I replace it with this.contacts = response.data;, I can print successfully.
what"s the reason? the gods ask for advice