首页 > 解决方案 > 带有 vue.js、quasar 和 ES6 的数组理解合成器

问题描述

我想在我的类星体项目中使用数组理解。Quasar 版本:0.17.* Vue.js 版本:2.9.6,使用 es6(又名 ES2015)

当我使用:

let newList = oldList.map(function (item) { return item.value })

一切都按预期工作。但是当我使用:

let newList = [for (item of oldList) item.value]

我得到以下信息synthax error

Failed to compile.

[...]

  13:26  error  Parsing error: Unexpected token

  11 | export function setList (state, oldList) {
  12 |   
> 13 |   let newList = [for (item of oldList) item.value]
     |                  ^
  14 |  

为什么 ?这个合成器不应该也是正确的吗?

标签: javascriptvue.jsecmascript-6quasar-framework

解决方案


推荐阅读