uni.navigateTo传对象参数的时候,数据类型为对象的时候出错,通过查资料总结出传参类型。
1、字符串拼接,传递单个属性值
data(){
return{
companyOrgId: 1
}
}
methods:{
goRegister() {
uni.navigateTo({
url: `./registerDetail?companyOrgId=${this.companyOrgId}`
});
},
}
onLoad(options) {
this.info.companyOrgId = options.companyOrgId;
console.log(options.companyOrgId);
},
2、整个对象的传递
data(){
return{
info: {
companyOrgId: '',
sex: 0,
surname: '',
firstname: '',
email: '',
phone: '',
phoneAreaCode: '+852',
password: '',
passwordTwo: '',
birthYear: 'YY',
birthMonth: 'MM',
birthDay: 'DD'
},
}
}
methods:{
goRegisterCode() {
console.log('info', this.info);
uni.navigateTo({
url: './registerCode?info=' + encodeURIComponent(JSON.stringify(this.info))
});
},
}
onLoad(options){
let userInfo = JSON.parse(decodeURIComponent(options.info));
console.log('userInfo', userInfo);
}
3、多个对象的传递
uni.navigateTo({
url: '/pages/setSeal/index?seal=' + encodeURIComponent(JSON.stringify(seal)) + '&cStorageModel' + encodeURIComponent(JSON.stringify(cStorageModel))
});
onLoad(option){
this.pageModel.sealAuth = JSON.parse(decodeURIComponent(option.sealAuth));
this.pageModel.cStorageModel = JSON.parse(decodeURIComponent(option.cStorageModel));
},