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:
- exportdefault {
- name:"app",
- data() {
- return {
- itemList:[]
- }
- },
- mounted() {
- this.getData();
- },
- methods:{
- getData() {
- this.$axios.get("../static/productList.json",{id:page1}).then(response => {
- this.itemList = response.data.result.list;
- });
- }
- }
- }