mock.js and introduction of local json file study notes

mock.js 


https://blog.csdn.net/Alcantara/article/details/78917846

Vue2.0 uses axios to introduce the pit of local JSON files


Today, I learned that Vue2.0 uses axios to introduce the pit of local JSON files.

1. How to import axios, import and prototype
  local JSON files need to be placed under the static folder. (and image files). See http://blog.csdn.net/Mr_YanYan/article/details/78783091
2.response is an Object object, but response.data is the object of the local JSON file
3.response.data is already an Object type; native JS writes The response returned by Ajax is string type
4. The JSON file must not have comments, otherwise it will return a string
5. If the JSON file has comments, JSON.parse will report an illegal character /. JSON files are originally objects, and then using
JSON.parse() will report an error containing illegal characters o

First offer the root component script:

[javascript] view plain copy
  1. exportdefault {   
  2.     name:"app",  
  3.     data() {  
  4.       return {  
  5.         itemList:[]  
  6.       }  
  7.     },  
  8.     mounted() {  
  9.       this.getData();  
  10.     },  
  11.     methods:{  
  12.       getData() {  
  13.         this.$axios.get("../static/productList.json",{id:page1}).then(response => {  
  14.           this.itemList = response.data.result.list;  
  15.         });  
  16.       }  
  17.     }  
  18.   } 

https://facebook.github.io/jest/docs/en/mock-functions.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325771620&siteId=291194637