Use uni.navigateBack(OBJECT) to pass parameters in uniapp

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right


Use uni.navigateBack(OBJECT) to pass parameters in uniapp


1. Knowledge before use


The getCurrentPages() function in uni-app is used to obtain the instance of the current page stack, which is given in the order of the stack in the form of an array, the first element is the home page, and the last element is the current page.

Note: getCurrentPages() is only used to display the status of the page stack, please do not modify the page stack to avoid page status error.


2. Application scenarios

Scenario: Jump from page A to page B, page B needs to close the current page and return to the previous level, and transfer it to page A


3. Use steps

1. In the method that needs to pass parameters on page B


let pages = getCurrentPages(); // 当前页页⾯实例
let nowPage = pages[pages.length -1]; //当前页⾯实例
let prevPage = pages[pages.length -2]; // 上一页面实例
// 需要返回 上一页的数据 Object
let object ={
    
    
	name:'zyz',
	mobile :'1831XXXXXXX'
};

prevPage.$vm.prevDateFun(object) // 调用上一页 定义的方法

// 返回 上一页
uni.navigateBack({
    
    
  delta:1 // 可以不写,默认值为 1
})

2. Page A uses prevDateFun to accept the assignment from page B


<script>
export default{
    
    
	data() {
    
    
		return {
    
    
		    name :'',
		    mobile :''
		}
	},
	 methods:{
    
    
		let _this =this
		
		// 方法名,是 B页面 定义的方法名称
		prevDateFun(object) {
    
    
			if(object){
    
    
			     _this.name = object.name 
			     _this.mobile = object.mobile    
			}else{
    
    
				return
			}
		},
	}
</script>

Summary 0.0

Guess you like

Origin blog.csdn.net/weixin_45344910/article/details/124928350