axios学习一如何使用axios

aixos基础用法

  <div>
        <button onclick="testGet()">GET请求</button>
        <button onclick="testPost()">POST请求</button>
        <button onclick="testPut()">PUT请求</button>
        <button onclick="testDelete()">DELETE请求</button>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
    <script>
        function testGet() { //GET请求
            axios.get(http://localhost:3000/posts).then(
                response => {
                    console.log(/posts, response.data);

                })
        }

        function testPost() { //POST请求
            axios.post(http://localhost:3000/posts, {
                "id": 5,
                "title": "balck-api",
                "author": "CCCC"
            }).then(
                response => {
                    console.log(/posts, response.data);

                })
        }

        function testPut() { //PUT请求
            axios.put(http://localhost:3000/posts/4, {
                "id": 4,
                "title": "happy-api",
                "author": "CCCC"
            }).then(
                response => {
                    console.log(/posts, response.data);

                })
        }

        function testDelete() { //DELETE请求
            axios.put(http://localhost:3000/posts/2).then(
                response => {
                    console.log(/posts, response.data);

                })
        }
    </script>

POST请求

axios学习一如何使用axios

 

 Delete请求

axios学习一如何使用axios

 

axios学习一如何使用axios

上一篇:如何实现BootStrapTable的动态表格插入与上下移动


下一篇:第四讲 网络八股拓展 -- mnist_app_ex