const { list = [] } = res.data || {};
list.length && (xxxxx)
报错
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'length')
const { list = [] } = res.data || {};
list.length && (xxxxx)
报错
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'length')
会,但是如果是 undefined 就不会了
默认值
每个解构属性都可以有一个默认值。当属性不存在或值为 undefined 时,将使用默认值。如果属性的值为 null,则不使用它。
13 回答12.8k 阅读
8 回答2.6k 阅读
2 回答5.1k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
5 回答902 阅读
5 回答1.2k 阅读✓ 已解决
3 回答2.2k 阅读