axios常用封装以及导入模块遇到的问题
axios封装
//post请求封装,其中url为请求路径,params为请求数据
export function post(url, params) {
return new Promise((resolve, reject) => {
axios.post(url, {data:params})
.then(resp => {
resolve(resp);
})
.catch(error => {
reject(error);
})
})
}
//get请求封装,其中url为请求路径,params为请求数据
export function get(url,params) {
return new Promise((resolve, reject) => {
axios.get(url, {params: params})
.then(resp => {
resolve(resp);
})
.catch(error => {
reject(error);
})
})
}
在引入封装的模块文件时,遇到使用import报错
解决方法:通过设置script标签的属性 type=module解决