GET
import axios from 'axios'
1---------------------------
getData(){
let config={
method:'GET',
params:{
page:this.page,
pagesize:this.pageSize,
},
}
axios(`${api.base}/getdata`,config).then(res=>{}).catch(()=>{})
}
2----------------------------
getData(){
let config={
params:{
page:this.page,
pagesize:this.pageSize,
},
}
axios.get(`${api.base}/getdata`,config).then(res=>{}).catch(()=>{})
}
3----------------------------
getData(){
let params={ //此变量名必须为params
page:this.page,
pagesize:this.pageSize,
}
axios.get(`${api.base}/getdata`,{params}).then(res=>{}).catch(()=>{})
}
4--------------------------
getData(){
axios.get(`${api.base}/getdata?page=${this.page}&pagesize=${this.pageSize}`).then(res=>{}).catch(()=>{})
}
POST
import axios from 'axios'
1---------------------------
postData(){
let config={
method:'POST',
}
data:{
name:this.name,
age:this.age
},
axios(`${api.base}/postdata`,data,config).then(res=>{}).catch(()=>{})
}
2----------------------------
postData(){
let data={
name:this.name,
age:this.age
}
axios.post(`${api.base}/postdata`,data).then(res=>{}).catch(()=>{})
}
3----------------------------
postData(){
let params = new FormData()
params.append("name",this.name)
params.append("age",this.age)
axios.post(`${api.base}/postdata`,params).then(res=>{}).catch(()=>{})
}
4--------------------------
postData(){
axios.post(`${api.base}/postdata?name=${this.name}&age=${this.age}`).then(res=>{}).catch(()=>{})
}