最近在做微信小程序,用的是uniapp开发的,自己记录一下,也和大家分享一下
1、字符串拼接,传递单个属性值
index页面传递:
data(){ return{ companyOrgId:1 } } methods:{ goRegister() { uni.navigateTo({ url: `./registerDetail?companyOrgId=${this.companyOrgId}` }); }, }
home页面接收:
1. onLoad(options) { 2. this.info.companyOrgId = options.companyOrgId; 3. console.log(options.companyOrgId); 4. },
2、整个对象的传递
index页面传递:
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)) }); }, }
home页面接收:
onLoad(options){ let userInfo = JSON.parse(decodeURIComponent(options.info)); console.log('userInfo', userInfo); }
3、多个对象的传递
index页面传递:
uni.navigateTo({ url: '/pages/setSeal/index?seal=' + encodeURIComponent(JSON.stringify(seal)) + '&cStorageModel' + encodeURIComponent(JSON.stringify(cStorageModel)) });
home页面接收:
onLoad(option){ this.pageModel.sealAuth = JSON.parse(decodeURIComponent(option.sealAuth)); this.pageModel.cStorageModel = JSON.parse(decodeURIComponent(option.cStorageModel)); },