params的传参方式
export const firstInterface= (params) => {
return request({
url: `xxx/xxx/xxx`, // 接口地址
method: 'post', // post || get
params
})
}
//调用页面 先引入再调用
const params = {xxxxx:yyy}
firstInterface(params).then(res=>{
console.log(res)
})
data的传参方式
export const secondInterface= (data) => {
return request({
url: `xxx/xxx/xxx`, // 接口地址
method: 'post', // post || get
data
})
}
//调用页面 先引入再调用
const data= {xxxxx:yyy}
secondInterface(data).then(res=>{
console.log(res)
})
params和data的传参方式
export const thirdInterface= (params,data) => {
return request({
url: `xxx/xxx/xxx`, // 接口地址
method: 'post', // post || get
params,
data
})
}
//调用页面 先引入再调用
const params = {xxx:yyy}
const data= {xxxx:yyyy}
thirdInterface(params,data).then(res=>{
console.log(res)
})
params和formData的传参方式
export const fourthInterface= (params,data) => {
return request({
url: `xxx/xxx/xxx`, // 接口地址
method: 'post', // post || get
params,
data,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
}
//调用页面 先引入再调用
const params = {xxx:yyy}
var formData = new FormData()
this.fileList.forEach(item => {
formData.append('files', item.raw) // this.fileList为文件数组
})
fourthInterface(params,formData).then(res=>{
console.log(res)
})
注意:formData上传要设置请求头;要设置请求头;要设置请求头
request.js自己封装axios请求的js配置