axios 封装

This commit is contained in:
”chenxuelian“
2022-12-24 16:44:08 +08:00
parent eeb0f904d1
commit b37ed47032
3 changed files with 12 additions and 4 deletions

View File

@@ -2,8 +2,12 @@ import App from './App'
//引入uView-ui组件库注意这两行要放在 import Vue 之后) //引入uView-ui组件库注意这两行要放在 import Vue 之后)
import uView from 'uview-ui' import uView from 'uview-ui'
import { apiService, toast } from "./service/request.js"
Vue.use(uView) Vue.use(uView)
Vue.prototype.$apiServe = apiService
Vue.prototype.$toast= toast
// #ifndef VUE3 // #ifndef VUE3
import Vue from 'vue' import Vue from 'vue'
Vue.config.productionTip = false Vue.config.productionTip = false

View File

@@ -99,6 +99,11 @@
//关闭下拉刷新 //关闭下拉刷新
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
}, },
onLoad() {
this.$apiServe.getCategories().then(res => {
console.log(res)
}).finally(_ => {})
},
methods: { methods: {
//点击一级分类 //点击一级分类
// click(listIndex) { // click(listIndex) {

View File

@@ -1,5 +1,5 @@
const serverHost = 'https://api-ugo-web.itheima.net' const serverHost = 'https://pupil.hchyun.com/api' // https://api-ugo-web.itheima.net'
function isOutTime(res) { function isOutTime(res) {
if (res.data.message === '请先登录') { if (res.data.message === '请先登录') {
uni.showToast('登录信息已过期,请重新登录') uni.showToast('登录信息已过期,请重新登录')
@@ -40,7 +40,6 @@ const service = {
}) })
}) })
}, },
post(url, data, isLogin) { post(url, data, isLogin) {
const header = {} const header = {}
if (isLogin) { if (isLogin) {
@@ -184,9 +183,9 @@ const apiService = {
}, },
// 获取 // 获取
getCategories(data) { getCategories(data) {
const url = `/api/public/v1/categories` const url = `/home/classlist`
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(service.get(url, data)) resolve(service.get(url))
}) })
}, },
// 新增 // 新增