The uniapp applet route jumps, using the uni.navigateBack method to realize jumping and passing parameters

Since the mini-program jump is limited to 10 layers, in order to reduce the page stack as much as possible, the uni.navigateBack() method will be used in the mini-program, and it is inevitable to encounter the problem of passing parameters between page jumps during use. uni.navigateBack is different from uni.navigateTo and uni.redirectTo, and parameters cannot be passed through route splicing. The following are three jump methods:

In the applet, uni.navigateTo and uni.redirectTo pass parameters through route splicing

uni.navigateTo({
    
    
	url: 'test?id=1&name=uniapp'
});
uni.redirectTo({
    
    
	url: 'test?id=1'
});

uni.navigateBack returns several layers through delta control

uni.navigateBack({
    
    
	delta: 2
});

Let's talk about how uni.navigateBack implements parameter passing?

The first method: pass the value through state management; (this method will not be demonstrated, save the value for the state management, and then get the value in onShow()) The second method: 1. Get
all the page stacks ; 2. Get the instance of the page to be jumped to; 3. Modify the parameter value in the data of the page to be jumped to by $vm;


Example:

下面示例是跳转上一页,然后给上一页data里面的参数传值

//当前页面
chosePhoto(item) {
    
    
	let pages = getCurrentPages(); //获取所有页面栈实例列表
	let nowPage = pages[pages.length - 1]; //当前页页面实例
	let prevPage = pages[pages.length - 2]; //上一页页面实例
    prevPage.$vm.idpositive = item; //修改上一页data里面的参数值
	prevPage.$vm.checkoutface = true; //修改上一页data里面的参数值
	uni.navigateBack({
    
     //uni.navigateTo跳转的返回,默认1为返回上一级
			delta: 1
		});		
	}
//上一页data参数
data() {
    
    
	return {
    
    
		idpositive: '../../static/idcard/idpositive.png',
		checkoutface: false, 
		}
    },

Guess you like

Origin blog.csdn.net/m0_47791238/article/details/130146353