[英]eslint - Use array destructuring in my vue project
I have a line like this this.report = newVal[0];
我有这样一行
this.report = newVal[0];
. . I'm looking at the documentation and I'm confused.
我正在查看文档,我很困惑。
example I have seen are like我见过的例子就像
const local = this.propslocal
const {local} = this.props
any ideas?有任何想法吗?
Take a look at this: eslint prefer-destructuring rule :看看这个: eslint prefer-destructuring rule :
This rule enforces usage of destructuring instead of accessing a property through a member expression.
此规则强制使用解构,而不是通过成员表达式访问属性。
As the examples you have seen, you should change your:正如你所看到的例子,你应该改变你的:
this.report = newVal[0]
To this instead:对此:
[this.report] = newVal;
To make it clear for you, if newVal
has 4 items, and you want to store first 2 items into different variables, instead of doing:为了让您清楚,如果
newVal
有 4 个项目,并且您想将前 2 个项目存储到不同的变量中,而不是执行以下操作:
const a = newVal[0];
const b = newVal[1];
Using destructuring, you should do:使用解构,你应该这样做:
const [a, b] = newVal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.