跳转界面
// 当前页面发起跳转,携带参数
function navigateWithParams() {
// 参数对象
const params = {
id: 123,
name: 'uniapp'
};
// 将参数转换为查询字符串
const queryString = Object.keys(params)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.join('&');
// 目标页面URL
const url = `/pages/target/target?${queryString}`;
// 使用uni.navigateTo跳转
uni.navigateTo({
url: url
});
}
接收界面
// 目标页面获取参数
export default {
onLoad: function(options) {
// options即为传递过来的参数对象
console.log(options.id); // 输出: 123
console.log(options.name); // 输出: uniapp
}
};