Home  >  Article  >  Web Front-end  >  How uniapp implements jump page to return data

How uniapp implements jump page to return data

coldplay.xixi
coldplay.xixiOriginal
2020-12-08 14:39:495580browse

Uniapp implements the method of returning data from the jump page: first pass the id to the click event; then write the method in Methods, the code is [uni.navigateTo({url:'opportunity-form?id=' id})]; Finally, receive parameters on the details page.

How uniapp implements jump page to return data

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, DELL G3 computer. This method is suitable for all brands of computers.

Recommended (free): uni-app development tutorial

uniapp implements jump page postback Data method:

First introduce the most original jump method, which is similar to the a tag in html, but in uniapp you need to replace the a tag with a5326a12123338c823426d0a96a021e0...9a67f2adf02d82de7f8f0475590779aa

Let’s focus on the method of jumping to pass value

1. Pass in the id to the click event

<view @tap="toOpportnity(item.id)">转商机</view>;

2. Write methods in Methods

toOpportnity(id){
uni.navigateTo({        //点击跳转的方法
url:&#39;opportunity-form?id=&#39;+id     //需要跳转的页面路径,使用问号进行id的传值,然后再拼接一个要传入的id//对象传参方式 url:&#39;../../pages/disabled/subsidie?listObj=&#39; + encodeURIComponent(JSON.stringify(obj))
})
}

3. Receive parameters on the details page

Write an onLoad function

onLoad(options){    //传入的参数名称,可自行修改
// console.log(options);    查看传入的id值

Receive method for object parameters

//this.leadobj(上个页面传过来的对象名称,即?后面的那个名称) = JSON.parse(decodeURIComponent(options.leadobj));   
}

The reception of a single parameter is introduced here using id

First of all, the passed id must be assigned a value

Request interface, the url address of the interface must be followed by the passed id id【/${this.id}/】

The complete steps are as follows:

onLoad(options){
this.id = options.id;
console.log(&#39;传过来的id值为:&#39; + options.id);
let that = this
uni.request({
url:`${this.$serverUrl}/opportunity/${this.id}/`,
header:{
&#39;Authorization&#39;: this.uerInfo.token
},
success(res){
console.log(res)
that.opportunity = res.data;
}
})
}对象传参报错解决方案

Related free learning recommendations: Programming video

The above is the detailed content of How uniapp implements jump page to return data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn