fix(api): 修复请求失败时未处理data为null的情况
当接口返回的data为null时,使用可选链操作符提供默认错误提示,避免undefined错误
Showing
1 changed file
with
2 additions
and
2 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-05-18 22:56:08 | 2 | * @Date: 2022-05-18 22:56:08 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-12 22:50:45 | 4 | + * @LastEditTime: 2025-09-16 21:56:59 |
| 5 | * @FilePath: /lls_program/src/api/fn.js | 5 | * @FilePath: /lls_program/src/api/fn.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -29,7 +29,7 @@ export const fn = (api, options = {}) => { | ... | @@ -29,7 +29,7 @@ export const fn = (api, options = {}) => { |
| 29 | // 只有在非静默模式下才显示错误提示 | 29 | // 只有在非静默模式下才显示错误提示 |
| 30 | if (!silent) { | 30 | if (!silent) { |
| 31 | Taro.showToast({ | 31 | Taro.showToast({ |
| 32 | - title: res.data.msg, | 32 | + title: res?.data?.msg || '请求失败', |
| 33 | icon: 'none', | 33 | icon: 'none', |
| 34 | duration: 2000 | 34 | duration: 2000 |
| 35 | }); | 35 | }); | ... | ... |
-
Please register or login to post a comment