通俗易懂的axios

get的两种请求:

                methods:{
                    //axios.get的发送参数有两种,两个ajax请求函数都可实现
                    sendGetByStr(){
                        //1.get通过直接发字符串拼接
                        axios.get(`get.php?name=${this.users.name}&age=${this.users.name}`)
.then(
function (response) { console.log(response.data); }) .catch(function (error) { console.log(error); }); }, sendGetByObj(){ //2.get通过params选项 axios.get(`get.php?`,{ params:{ name:this.users.name, age:this.users.age } })
.then(
function (response) { console.log(response.data); }) .catch(function (error) { console.log(error); }); } } })

post的一种

methods:{
                    sendPsot(){

                        axios.post('post.php', {
                            name: this.users.name,
                            age: this.users.age,
                          })

                          .then(function (response) {
                            console.log(response);
                          })
                          .catch(function (error) {
                            console.log(error);
                          });
                    }
                    
                }
原文地址:https://www.cnblogs.com/ll15888/p/11552352.html