在,小程序里头,登录错了,应该怎么重新,登录

1个回答

写回答

Hcusbks

2026-01-11 08:50

+ 关注

Ajax
Ajax

需要用代码。退出登陆操作:(1)点击“退出账号”按钮,调用Ajax请求后端退出登陆接口并传递用户token,若退出成功,则清除当前用户登陆状态和token信息。(2)刷新当前页面数据,清除页面上的用户信息。(3)后端API接收到客户端传递的用户token,查询数据库判断用户是否已登陆,若登陆,则删除或将token置为无效。前端代码为:const logout = function () {wx.showLoading({ title: '退出登陆中' })const token = wx.getStorageSync('token')Api.logout({ token: token }).then(data = {wx.hideLoading()wx.removeStorageSync('token')refreshPageData()})}后端代码为:async logout(accessToken) {const { ctx, app } = this;

const userId = awAIt app.redis.get(accessToken);if (!userId) ctx.throw(400, '登陆状态已失效');awAIt app.redis.del(userId); // 删除userIdawAIt app.redis.del(accessToken); // 删除token}

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号