1. <button>得到所有的省份数据</button>
    2. <script>
    3. let req;
    4. function getRequestInfo() {
    5. if (!req) {
    6. const url = "http://101.132.72.36:5100/api/local";
    7. req = new Request(url, {});
    8. console.log(req);
    9. }
    10. return req.clone(); //克隆一个全新的request对象,配置一致
    11. }
    12. async function getProvinces() {
    13. // const resp = await fetch(getRequestInfo())
    14. const resp = new Response(`[
    15. {"id":1, "name":"北京"},
    16. {"id":2, "name":"天津"}
    17. ]`, {
    18. ok: true,
    19. status: 200
    20. })
    21. const result = await getJSON(resp);
    22. console.log(result)
    23. }
    24. async function getJSON(resp) {
    25. const json = await resp.json();
    26. return json;
    27. }
    28. document.querySelector("button").onclick = function() {
    29. getProvinces();
    30. }
    31. </script>