使用接口:
https://api-hmugo-web.itheima.net/api/public/v1/home/floordata
import axios from "axios";
const instance=axios.create({
//这里是接口公共的url部分,会拼接在url参数前面
baseURL:"https://api-hmugo-web.itheima.net/api/public/v1",
timeout:5000,
})
export function get(url,params){
return instance.get(url,{
params
});
}
export function post(url,data){
return instance.post(url,data);
}
export function del(url){
return instance.get(url);
}
export function put(url,data){
return instance.put(url,data);
}
这里使用baseURL存放公共的url地址
调用:
get("/home/floordata",{}).then(res=>{
console.log(res)
})