Axios 安装配置

参考地址https://www.kancloud.cn/yunye/axios/234845、


npm install axios

安装axios在项目中

在main.js配置内容

import axios from 'axios'

Vue.prototype.$axios = axios

配置qs解码(post)

import qs from 'qs'

Vue.prototype.$qs = qs



使用:

url路径

method传值方式post、get

params传值参数

.then 里是后台返回结果

 .catch里是网络错误或后台服务器出bug等等


第一种

created(){

                            this.$axios({

                                     url:'https://dawn.changxvan.top/api/Order/order_details',

                                     params:{

                                               //id:274696

                                               id:2,

                                               order_id:3

                                     }

                            }).then((s)=>{

                                     console.log(s.data)

                                     }).catch((e)=>{

                                               console.log(e)

                                     })

                   },

第二种

created(){

                            this.axios({

                                     url:'https://dawn.changxvan.top/api/Order/order_details',

                                     params:{

                                               //id:274696

                                               id:2,

                                               order_id:3

                                     }

                            }).then(function(rel){

                                     console.log(rel)

                            }).catch(function(err){

                                     console.log(err)


                            })

                   },

你可能感兴趣的:(Axios 安装配置)