Looking to retrieve data from a JSON file with the json data format.
[{"id":81,"body":"There are some reason to fix the issues","created_at":"2017-11-16 11:56:47","updated_at":"2017-11-16 11:56:47"}]
I have integrated vue-resource and followed the Vue syntax correctly.
import vueResource from 'vue-resource'
Vue.use(vueResource)
In my userlist component, I am attempting the following script
export default {
data:function(){
return {
list:[],
car:{
id:'',
body:''
}
};
},
created: function(){
this.fetchCarList();
},
methods:{
fetchCarList: function(){
this.$http.get('http://localhost:8080/api.js').then(function(response){
this.list = response.data
});
}
}
}
And here is the HTML loop for the component
<ul id="example-1">
<li v-for="item in list">
{{ item.body }}
</li>
</ul>
I have verified that http://localhost:8080/api.js
returns the data correctly. However, when using the get() method in the fetchCarList function, it does not work as expected. It works fine if I add the JSON data directly in the code.
How can I troubleshoot and resolve this issue?