1、utils/request.js
import axios from "axios";
let service = axios.create({
baseURL: "https://v4.crmeb.net/api",
timeout: 5000
})
export default service
2、api/product.js
import service from "@/utils/request.js"
// 轮播图
// get
export const GetBanner = (params) => {
return service({
url: "/pc/get_banner",
method: "get",
params
})
}
// 导航,分类
// get
export const NavDatas = (data) => {
return service({
url: "/category",
method: "get",
data
})
}
// 商品数据
// get
export const ShopDatas = (params) => {
return service({
url: "/pc/get_category_product",
method: "get",
params
})
}
// 登录
// post
// export const LoginApi = (data) => {
// return service({
// url: "/pc/get_banner",
// method: "post",
// data
// })
// }
3、页面
import { GetBanner } from "@/api/product.js";
//方法集合
methods: {
//轮播图的index
handleChange(index) {
console.info(index);
},
//获取轮播图的数据
async banDatas() {
let result = await GetBanner();
this.bannerDatas = result.data.data.list;
return;
},
},
//生命周期 - 挂载完成(可以访问DOM元素)
mounted() {
this.banDatas();
},