在react项目中使用可选链配置
时间:2020-01-14 13:10:33
收藏:0
阅读:612
```javascript
componentDidMount() {
let a = { b: 1, c: 2, d: [1, 2, 3] }
console.log(a?.d?.length ?? 0)
}
````
在babel配置中添加两个包即可:
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
原文:https://www.cnblogs.com/JC-Liu/p/12191020.html
评论(0)