首页 > 解决方案 > 解析错误:意外的令牌/表达式预期.ts(1109)

问题描述

我正在尝试通过编写以下代码来模块化我的 Vuex 商店

import state from './state'
import * as getters from './getters'
import * as mutations from './mutations'
import * as actions from './actions'

export const recoSideB = {
  namespaced: true,
  state = { ... } ,
  mutations= {... },
  actions= { ... },
  getters= { ... }
}

但是得到 Expression Expected.ts(1109) 我在 eslint 中尝试了以下配置更改

parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module',
    ecmaVersion: 6,
    ecmaFeatures: {
      "experimentalObjectRestSpread": true
    }
  },

根据 https://stackoverflow.com/a/36003974/7596740的回答

但仍然面临解析问题

在此处输入图像描述

标签: vue.jsecmascript-6vuexeslintvuex-modules

解决方案


发生错误,因为您的对象不正确。

你的对象是:

export const recoSideB = {
  namespaced: true,
  state = { ... } ,
  mutations= {... },
  actions= { ... },
  getters= { ... }
}

但正确的版本必须是:

export const recoSideB = {
  namespaced: true,
  state :{ ... } ,
  mutations:{... },
  actions:{ ... },
  getters:{ ... }
}

推荐阅读