uniapp路由传递数组对象报错Unexpected end of JSON input

110 阅读1分钟

原因
在网上找到了答案是因为传递的参数中有识别不到的内容,我传递的参数里面包含了富文本,所以没有解析出来

解决办法
A页面

if(id && id !== 0) {
        let items = encodeURIComponent(JSON.stringify(this.videoList));
        uni.navigateTo({
                url:"/pages/classroom/info?id="+id + '&videoList=' + items
        })
}

B页面

onLoad(options) {
            this.getVideoInfo(options.id)
            if(options.videoList) {
                    this.videoList = JSON.parse(decodeURIComponent(options.videoList))
                    console.log(this.videoList);
            }
    },

总结:最主要的是encodeURIComponentdecodeURIComponent