z为了统管理请求axios 路径 ,两种封装axios的思路
1.封装两个方法用这两个方法来管理请求路径
import axios from "axios"
const instance = axios.create({
baseURL: 'http://localhost:8080/data/',
timeout: 3000,
// headers: {'X-Custom-Header': 'foobar'}
});
export function httpGet(url,params){
return instance.get(url,{
params:params
})
}
export function httpPost(url,data){
return instance.post(url,data)
}
封装项目中路径
const urls={
AAS_MYAPPS_URL: "/apps.json",
AAS_ALLAPPS_URL: "/allapps.json",
AAS_PERSONAL_INFO_URL: "/user.json" ,
AAS_STUS_URL: "/stus.json",
ALL_STUDENT_URL: "stus.json"
}
export default urls
使用
//导入
import {httpGet} from "../request/index.js"
import urls from "../request/urls.js"
//请求数据
getinfo(){
httpGet(urls.ALL_STUDENT_URL).then(res=>{
this.tableData=res.data
})
},