uniapp 有些场景页面之间跳转需要带参 参数过短一般能够接收到 但是参数过长的情况下会遇到参数被截取 获取不到完整的参数 这个时候需要用到uniapp提供的encodeURIComponent和decodeURIComponent这个语法
用例如下 index页面跳转demo页面
<template>
<view>
<button @click="todemo">跳转</button>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad() {
},
methods: {
todemo() {
// 此为demo案例
const params = {id:1,name:'xxxxx',sex:'boy',desc:'xxxxxxx',age:99}
uni.navigateTo({
// 先将params转成字符串 再进行编码
url:'/pages/demo/demo?params=' + encodeURIComponent(JSON.stringify(params))
})
}
}
}
</script>
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
},
onLoad(option) {
// 先解码 再将字符串转成对象
const params = JSON.parse(decodeURIComponent(option.params))
console.log(params)
}
}
</script>
<style>
</style>