From b37ed47032ba0f8a4471581e4ba1d99ff3506877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Dchenxuelian=E2=80=9C?= <“chenxuelian@cjiedata.com”> Date: Sat, 24 Dec 2022 16:44:08 +0800 Subject: [PATCH] =?UTF-8?q?axios=20=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 4 ++++ pages/index/index.vue | 5 +++++ service/request.js | 7 +++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 0118bf5..817cf67 100644 --- a/main.js +++ b/main.js @@ -2,8 +2,12 @@ import App from './App' //引入uView-ui组件库(注意这两行要放在 import Vue 之后) import uView from 'uview-ui' +import { apiService, toast } from "./service/request.js" Vue.use(uView) +Vue.prototype.$apiServe = apiService +Vue.prototype.$toast= toast + // #ifndef VUE3 import Vue from 'vue' Vue.config.productionTip = false diff --git a/pages/index/index.vue b/pages/index/index.vue index 0bb33dc..e942a49 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -99,6 +99,11 @@ //关闭下拉刷新 uni.stopPullDownRefresh() }, + onLoad() { + this.$apiServe.getCategories().then(res => { + console.log(res) + }).finally(_ => {}) + }, methods: { //点击一级分类 // click(listIndex) { diff --git a/service/request.js b/service/request.js index 1cbc593..51b49ee 100644 --- a/service/request.js +++ b/service/request.js @@ -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) { if (res.data.message === '请先登录') { uni.showToast('登录信息已过期,请重新登录') @@ -40,7 +40,6 @@ const service = { }) }) }, - post(url, data, isLogin) { const header = {} if (isLogin) { @@ -184,9 +183,9 @@ const apiService = { }, // 获取 getCategories(data) { - const url = `/api/public/v1/categories` + const url = `/home/classlist` return new Promise((resolve, reject) => { - resolve(service.get(url, data)) + resolve(service.get(url)) }) }, // 新增