小程序 用户登录过期操作

timeOut: function () {
     var that = this;
     setInterval(function () {
       that.request('',
         {},
         'GET',
         function (res) {
           if (!res.data.data) {
             wx.showToast({
               title: '用户未登录或已过期,请重新登录!',
               icon: 'none',
               duration: 3000,
               mask: false,
               success: function () {
                 wx.removeStorageSync('token');
                 wx.removeStorageSync('userName');
                 wx.removeStorageSync('userPassword');
                 setTimeout(function () {
                   wx.navigateTo({
                     url: '',
                   })
                 }, 2000)

               },
             })
           }
         }, function () {
           console.log("失败")
         }
       );
     }, 300000);
  },

此时此刻 你只需要把这段代码放进你的app。js 中 换上你的接口  就好了  wx.removeStorageSync  删除登录的存储信息

你可能感兴趣的:(小程序 用户登录过期操作)