在pages.json 里面配置注册这两个页面,配置的代码我就省略啦
1.A页面
<template>
<button @click="navBar()">传递信息</button>
</template>
<script>
export default {
data() {
return {}
},
methods: {
navBar() {
let obj = {
name: '小红',
age: 21,
sex: '女'
};
// 加密传递的对象数据
let item = encodeURIComponent(JSON.stringify(obj))
uni.navigateTo({
url: '/pages/index/index?item=' + item
})
}
}
}
</script>
2.B页面(接收传递过来的对象的页面),我这边B页面路径是/pages/index/index,具体页面跳转路径根据自己的项目编写!
<template>
<view>
接收的信息
<view>
<text>{{info.name}}</text>
<text>{{info.age}}</text>
<text>{{info.sex}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
info: {}
}
},
onLoad: function(option) {
// decodeURIComponent 解密传过来的对象字符串
this.userObj = JSON.parse(decodeURIComponent(option.item));
}
}
</script>