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