uniapp page jump parameters are incomplete

Some uniapp scenes need to jump between pages with parameters. The parameters are too short and generally can be received, but when the parameters are too long, the parameters will be intercepted and the complete parameters cannot be obtained. In this case, the encodeURIComponent and decodeURIComponent provided by uniapp need to be used.

For example, the following index page jumps to the demo page

<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>

Guess you like

Origin blog.csdn.net/Dajdhushvj/article/details/125494535