0
点赞
收藏
分享

微信扫一扫

uniapp实现tabbar页面跳转前进行拦截

老北京的热干面 2022-02-09 阅读 129

遇到的需求:进入小程序wxlogin请求成功后请求另外一个接口会获取一个字段值,根据这个值判断能否跳转到第二个tabaar页面并给出相应的提示.

使用uni.addInterceptor

跳转拦截

创建intercept.js

//拦截器 拦截judge值等于空的时候 想要跳转到白名单内的路径时,不能跳转并给出提示
import store from '@/store'
// 白名单页面名单  可以配置多个
const whiteList = [
	'/pages/life/index',
]
uni.addInterceptor('switchTab', {
	// tabbar页面跳转前进行拦截
	invoke(e) {
		var that=this
		var judge=that.vuex_user.judge
		if ( !judge && e.url == whiteList[0]) {
			uni.showToast({
			    title: '正在获取用户信息',
				icon: "none",
			    duration: 1000
			});
			// 	uni.switchTab({
			// 		url: '/pages/home/home'
			// 	});
			return false
		} else {
			return true
		}
	},
	success(e) {
		// console.log(e)
	},
	fail(err){
	    // console.log(err)
	}
})
举报

相关推荐

0 条评论