request:fail parameter error: parameter.url should be String instead of Undefined;

博主在项目中遇到滑动到特定位置时触发的接口调用错误,通过逐步注释代码和重启开发环境,最终定位到API请求路径变量被误删除的问题,并分享了解决问题的心得。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 项目接过来突然报这些被折磨死了:上网查各种奇怪的答案的都有还是没有解决

静下心挨个注释页面只剩导航切换了,还是报错我就纳闷了。

周末回家挨个注释, 项目重启,开发工具重启(为了去掉缓存之类的)

结果定位到每次滑倒下面一定距离,这个是猜你喜欢的那块分页的逻辑, 然后下滑请求接口注释就不报错了,后来请求接口参数,url打印发现引入url变量undefined ,找到api定义的文件发现变量请求路径被人删了,重新加上就好了。坑爹的问题:

解决问题的思路和心清气和很重要。周末在家一遍胡吃海喝,一边打游戏,放松完事再看问题,解决了。

 

转载于:https://www.cnblogs.com/pikachuworld/p/11565552.html

select(files) { const newFiles = files.tempFiles.map(file => ({ name: file.name, url: file.path, extname: file.extname, size: file.size })); this.fileList = [...this.fileList, ...newFiles]; }, // 文件删除回调 deleteFile(file) { const index = this.fileList.findIndex(f => f.url === file.url); if (index !== -1) { this.fileList.splice(index, 1); } }, async handleSubmit(value){ console.log(this.fileList); // 检查图片数量是否符合要求 (2-6张) if (this.fileList.length < 2) { uni.showToast({ title: '请至少上传2张图片', icon: 'none', position: 'top' }); return; } if (this.fileList.length > 6) { uni.showToast({ title: '最多只能上传6张图片', icon: 'none', position: 'top' }); return; } // 1. 修正微信临时路径格式 const fixWxFilePath = (path) => { if (!path) return path; // 处理微信开发者工具的特殊路径 if (path.startsWith('http://tmp/')) { return `wxfile://tmp_${path.split('/').pop().split('.')[0]}`; } // 处理真机环境的过长路径 if (path.startsWith('wxfile://tmp_') && path.length > 45) { // 提取正确的32位hash const match = path.match(/wxfile:\/\/tmp_([a-f0-9]{32})/); if (match && match[1]) { return `wxfile://tmp_${match[1]}`; } // 简易截断方案 return `wxfile://tmp_${path.substring(13, 45)}`; } return path; }; // 2. 验证和修正文件列表 const validFiles = this.fileList .filter(Boolean) .map(file => { // 获取原始路径 const origUrl = file.url || file.path || file.tempFilePath || file.uri; return { ...file, url: fixWxFilePath(origUrl), origUrl }; }) .filter(file => file.url && typeof file.url === 'string' && file.url.trim() !== '' && file.url.startsWith('wxfile://tmp_') ); // 3. 详细错误报告 if (validFiles.length !== this.fileList.length) { const badFiles = this.fileList.filter(f => !validFiles.some(vf => vf.origUrl === (f.url || f.path || f.tempFilePath || f.uri)) ); console.error('无效文件:', badFiles); uni.showToast({ title: `发现 ${badFiles.length} 个无效文件`, icon: 'none', duration: 3000 }); return; } // 4. 创建上传参数前的最终验证 const filesParam = validFiles.map(file => { if (!file || !file.url) return null; // 前置空值检查 const filePath = file.url; return { name: 'attachments', filePath: filePath }; }).filter(Boolean); // 如果修正后文件数量变化 if (filesParam.length !== validFiles.length) { uni.showToast({ title: `${validFiles.length - filesParam.length}个文件路径格式无效`, icon: 'none', duration: 3000 }); return; } console.log('上传参数:', filesParam); try{ const afterOrderData = { contactName:this.form.name, contactTelephone:this.form.mobile, contactAddress:this.form.address, name:this.form.productname, type:'2', contractId:this.form.contract, fixId:this.form.maincontract, deviceModel:this.form.deviceModel, deviceProblem:this.form.describe, } const afterOrderStr = JSON.stringify(afterOrderData); console.log(filesParam,'o'); const res = await uni.uploadFile({ url:`${BASEURL}/api/afterOrders`, method:'POST', header:{ 'Authorization': `Bearer ${this.token}` }, formData:{ afterOrder: afterOrderStr }, files:filesParam }) console.log(res); 难道我这里的处理不对吗
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值