请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

在注册页面,自动跳转到登录页面

写完定时器之后,我在注册页面停留5秒,他会自动跳转到登录页面,请问这个是怎么回事?

  1. 我在注册页面,等5秒左右
    图片描述

  2. 自动跳转到登录页面
    图片描述

index页面的js代码

<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue';
import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
export default {
	components: {
		uniPopup,
		uniPopupMessage,
		uniPopupDialog
	},
	data() {
		return {
			title: 'Hello',
			timer: null,
			unreadRows: 0,
			lastRows: 0
		};
	},
	onLoad:function() {
		// 监听事件
		let that = this;
		uni.$on('showMessage', function() {
			that.$refs.popupMsg.open();
		});
	},
	onUnload:function() {
		// 移除监听事件
		uni.$off('showMessage');
	},
	onShow: function() {
		let that = this;
		that.timer = setInterval(function() {
			that.ajax(that.url.refreshMessage, 'GET', null, function(resp) {
				that.unreadRows = resp.data.unreadRows;
				that.lastRows = resp.data.lastRows;
				

				if (that.lastRows > 0) {
					uni.$emit('showMessage');
				}
			});
		}, 5 * 1000);
	},
	onHide:function() {
		clearInterval(this.timer);
	},
	methods: {
		toPage: function(name, url) {
			//TODO 验证用户的权限
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

register页面的js代码

<script>
export default {
	data() {
		return {
			registerCode: null
		};
	},
	methods: {
		register: function() {
			let that = this;
			if (that.registerCode == null || that.registerCode.length == 0) {
				uni.showToast({
					title: '邀请码不能为空',
					icon: 'none'
				});
				return;
			} else if (/^[0-9]{6}$/.test(that.registerCode) == false) {
				uni.showToast({
					title: '邀请码必须是6为数字',
					icon: 'none'
				});
				return;
			}

			uni.login({
				provider: 'weixin',
				success: function(resg) {
					let code = resg.code;
					console.log(code);
					uni.getUserInfo({
						provider: 'weixin',
						success: function(resp) {
							let data = {
								code: code,
								nickname: '默认用户名称',
								photo: 'https://1233.jpg',
								registerCode: that.registerCode
							};

							that.ajax(that.url.register, 'POST', data, function(resp) {
								let permission = resp.data.permission;
								uni.setStorageSync('permission', permission);
								console.log(permission);
								//TODO 跳转到index页面
								uni.switchTab({
									url: '../index/index'
								});
							});
						}
					});
				}
			});
		}
	}
};

正在回答

1回答

你没有登录系统,拉取消息的时候必定会让你登录,登录之后才会有Token,这样才能拉取消息

0 回复 有任何疑惑可以回复我~
  • 提问者 慕前端5583653 #1
    怎么让他在登录之后在拉取信息呢,用户会有没有登录的场景
    回复 有任何疑惑可以回复我~ 2025-01-21 21:10:43
  • 神思者 回复 提问者 慕前端5583653 #2
    在定时器里面加一个判断就行了,本地没有token就不发送请求
    回复 有任何疑惑可以回复我~ 2025-01-22 10:00:50
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号