When doing the Uniapp project, the function of jumping between pages will be used. There are several points and pits. Now summarize.

  • Switching from page A to Page B
    uni.navigateTo({ url:`.. /myTicket/scanRecharge/scanRecharge? qrcode=${res.result}`})Copy the code

    B Page receiving parameters:

    onLoad(option) {
       this.qrcode = option.qrcode + '='This.getscanresult ()} Note: this column is the result of the TWO-DIMENSIONAL code in the URL address, using onLoad method, will automatically truncate the last "=" of the two-dimensional code, such as the two-dimensional code as interface parameters need to manually splice "="Copy the code
  • So, how to pass the parameter from page B to page A?
    B Page code: Var pages = getCurrentPages() // prevPage = pages[pages.length-2] // PrevPage. SetData ({// assign chooseName to the previous page directly: NavigateBack ({delta: 1}) {navigateBack({delta: 1}) {navigateBack({delta: 1}) {navigateBack({delta: 1})}) {navigateBack({delta: 1})}}onShow() {this.pages = getCurrentPages() this.currPage = this.pages[this.pages.length-1] // Current page // With this directly. CurrPage. Passed the data to get B page data enclosing chooseName = this. CurrPage. Data. ChooseName},Copy the code

    Note:

    1: name must be A page data defined field!

    2. The event to receive the return must be written in the onShow method.

    3. NavigateTo must be used to jump to B page, this method will retain the previous page, other methods will destroy the current page, otherwise can not get the current stack!