Axios
Axios 原生ajax 1 2 3 4 5 6 7 8 9 10 11 function getdoc() { var doc = new XMLHttpRequest(); doc.open('GET', 'http://path'); //形如:http://yapi.smart-xwork.cn/mock/169327/emp/list doc.send(); doc.onreadystatechange = function () { if (doc.readyState == 4 && doc.status == 200) { document.getElementById('div').innerHTML = doc.responseText; } } } 测试环境部署: 前置npm设置: 1 npm config ls 到prefix="…",将改路径加入到path环境变量中即可 json-server配置: 1 npm install -g json-server 建立db.json文件,并在内输入 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { "posts": [ { "id": 1, "title": "json-server", "author": "typicode" } ], "comments": [ { "id": 1, "body": "some comment", "postId": 1 } ], "profile": { "name": "typicode" } } 然后在相应目录运行并启动服务器 ...