vue.js - eslint - 在我的 vue 项目中使用数组解构
问题描述
我有这样一条线this.report = newVal[0];
。我正在查看文档,我很困惑。
我见过的例子就像
const local = this.propslocal
const {local} = this.props
有任何想法吗?
解决方案
看看这个:eslint prefer-destructuring rule:
此规则强制使用解构而不是通过成员表达式访问属性。
正如您所看到的示例,您应该更改:
this.report = newVal[0]
为此:
[this.report] = newVal;
为了让您清楚,如果newVal
有 4 个项目,并且您想将前 2 个项目存储到不同的变量中,而不是这样做:
const a = newVal[0];
const b = newVal[1];
使用解构,你应该这样做:
const [a, b] = newVal;
推荐阅读
- c# - 双击与单击
- xamarin - Xamarin.Forms 应用程序中的 Voice Over 是否区分 Android 和 iPhone 上的启用和禁用按钮状态?
- php - PHP多维数组按条件搜索
- java - 如何在多租户系统中切换 jpa 方言以指定租户
- r - 改变由转换为符号的字符串选择的列
- contao - Contao 是否可以不重定向到主页别名?
- amazon-ec2 - EC2 `UserData` 执行挂起在`Checking init scripts...`
- android - 当 minifyEnabled 在 gradle 中设置为 true 时,RXJava subscribe 方法抛出 NullPointerException
- laravel - 是否可以在创建授权资源中添加一些参数?
- android - 如何在andoird中使用MaterialDatePicker