From 827084be9d75230d2d461e0d04f6927fdf21f0ea Mon Sep 17 00:00:00 2001 From: xuan <3142316616@qq.com> Date: Wed, 18 Dec 2024 01:23:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E9=80=9A=E4=BF=A1=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/axiosConfig.js | 4 +-- src/views/chat/chat.vue | 37 ++++++++++++++++++++++++ vue.config.js | 62 ++++++++++++++++++++++++---------------- 3 files changed, 76 insertions(+), 27 deletions(-) diff --git a/src/utils/axiosConfig.js b/src/utils/axiosConfig.js index a6561ad7..df07b0c2 100644 --- a/src/utils/axiosConfig.js +++ b/src/utils/axiosConfig.js @@ -4,8 +4,8 @@ import {getToken} from '@/token/auth' // 注意这里使用了解构赋值来导 // 创建axios实例 const service = axios.create({ - // baseURL: 'http://47.122.59.26:8080/api', - // baseURL: 'http://10.205.10.22:8081/loveforest/api/', + // 去vue.config.js文件改baseurl!! + baseURL: '/api', // 注意!! 这里全局统一加上了 '/api' 前缀,但是vue.config.js文件在发送请求时去掉了/api,所以页面的请求接口若有/api还是要携带/api timeout: 5000, // 请求超时时间 }); diff --git a/src/views/chat/chat.vue b/src/views/chat/chat.vue index 8e8e8fae..028a73a9 100644 --- a/src/views/chat/chat.vue +++ b/src/views/chat/chat.vue @@ -176,6 +176,7 @@ export default { this.showSearchList = this.friendsInfoList this.get_friendsInfoList() + this.long_poll_serve() }, components:{ HonneyBtn, @@ -184,6 +185,42 @@ export default { ChatList }, methods:{ + async long_poll_serve(){ + try{ + const UserId = getUserId() + const token = 'Bearer '+getToken() + const response = await axios.get(`messages/poll/${UserId}`,{ + headers:{Authorization : token} + }) + if(response.data == '') + { + this.long_poll_serve() + }else{ + const senderId = response.data[response.data.length-1].senderId + console.log(senderId) + for(let i = 0;i