json-server返回结果如下图
vue 访问为:
created() {
this.readJsonFile();
},
methods: {
readJsonFile() {
let res=this.$http.get('http://localhost:3000/data');
console.log(res);
console.log(res.body}
}
结果为:
这是由于异步引起的。做异步处理即可!
async readJsonFile() {
let res= await this.$http.get('http://localhost:3000/data');
console.log(res);
console.log(res.body);
}