一、axios get请求
axios. get ( url[ , config] ) . then ( response => { } ) . catch ( error => { } ) ;
axios. get ( 'https://api.example.com/data' ) . then ( response => { } ) . catch ( error => { } ) ;
url:即请求api 链接; [, config]:表示config 可有可无
axios get请求 一 config 参数(常用)
axios. get ( 'https://api.example.com/data' , { params : { "username" : "test" , } , headers : { "Content-Type" : "application/json" , } , timeout : 1000 ,
} ) . then ( response => { } ) . catch ( error => { } ) ;
二、axios post
axios. post ( url, data[ , config] ) . then ( response => { } ) . catch ( error => { } ) ;
axios. post ( 'https://api.example.com/data' , { firstName : 'Fred' , lastName : 'Flintstone'
} ) . then ( response => { } ) . catch ( error => { } ) ;
url:即请求api 链接; data:传递的参数,object { } 形式; [, config]:表示config 可有可无
axios post请求 一 config 参数(常用)
axios. post ( 'https://api.example.com/data' , data, { data : { firstName : 'Fred' } , headers : { "Content-Type" : "application/json" , } , timeout : 1000 ,
} ) . then ( response => { } ) . catch ( error => { } ) ;
三、axios() 发起请求
axios ( { method : 'get/post' , url : '/data' , baseURL : 'https://api.example.com' , params : { } , data : { } , headers : { } , timeout : 100 , } ) . then ( response => { } ) . catch ( error => { } ) ;
四、axios 创建实例