【问题标题】:eslint - Use array destructuring in my vue projecteslint - 在我的 vue 项目中使用数组解构
【发布时间】:2020-04-25 08:02:05
【问题描述】:

我有这样一行this.report = newVal[0];。我正在查看文档,我很困惑。

我见过的例子是这样的

const local = this.propslocal
const {local} = this.props

有什么想法吗?

【问题讨论】:

  • 你为什么要改变它?
  • eslint 和它有什么关系,你到底遇到了什么问题?
  • b/c 我们有一个 linter,它抛出 Use array destructuring.eslint(prefer-destructuring) 错误,我查看了很多示例,但无法弄清楚

标签: vue.js eslint


【解决方案1】:

看看这个: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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 2021-02-23
    • 2021-12-14
    • 2019-12-27
    • 2021-01-02
    • 1970-01-01
    • 2019-07-16
    • 2021-07-19
    相关资源
    最近更新 更多