首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >左括号和右方括号中的",expected“,ESLint和JavaScript

左括号和右方括号中的",expected“,ESLint和JavaScript
EN

Stack Overflow用户
提问于 2018-07-01 23:11:05
回答 1查看 269关注 0票数 0

我已经在这个问题上工作了大约三个小时,但我找不到我做错了什么,也找不到如何修复它。我搜索了堆栈,但没有找到任何东西,我不确定这是语法还是我在编程中做了一些与语法无关的可怕的错误(逻辑错误等)。我对JS和stackoverflow都是新手,所以如果我的格式、问这个问题的方式或一般的问题不正确,我深表歉意。

代码语言:javascript
复制
import Vue from 'vue'
import Vuex from 'vuex'
import sourceData from '@/data'
import {countObjectProperties} from '@/utils'

Vue.use(Vuex)

const makeAppendChildToParentMutation = ({parent, child}) =>
    (state, {childId, parentId}) => {
      const resource = state[parent][parentId]
        if (!resource[child]) {
          Vue.set(resource, child, {})
        }
      Vue.set(resource[child], childId, childId)
    }
export default new Vuex.Store({

  state: {
    ...sourceData,
    authId: 'VXjpr2WHa8Ux4Bnggym8QFLdv5C3'
  },

  getters: {
    authUser (state) {
      return state.users[state.authId]
    },

      userThreadsCount: state => id => countObjectProperties(state.users[id].threads),
      userPostsCount: state => id => countObjectProperties(state.users[id].posts)
    },
  actions: {
    createPost ({commit, state}, post) {
      const postId = 'greatPost' + Math.random()
      post['.key'] = postId
      post.userId = state.authId
      post.publishedAt = Math.floor(Date.now() / 1000)
      commit('setPost', {
                  postId: id,
                  post: {
                    ...post,
                      text,
                      edited: {
                        at: Math.floor(Date.now() / 1000),
                          by: state.authId
                      }
                  }
              })
      commit('appendPostToThread', {threadId: post.threadId, postId})
      commit('appendPostToUser', {userId: post.userId, postId})
      return Promise.resolve(state.posts[postId])
    },
    createThread ({state, commit, dispatch}, {text, title, forumId}) {
      return new Promise((resolve, reject) => {
        const threadId = 'greatThread' + Math.random()
          const userId = state.authId
          const publishedAt = Math.floor(Date.now() / 1000)
      const thread = {'.key': threadId, title, forumId, publishedAt, userId}
      commit('setThread', {threadId, thread})
      commit('appendThreadToForum', {forumId, threadId})
      commit('appendThreadToUser', {userId, threadId})
      dispatch('createPost', {text, threadId})
        .then(post => {
          commit('setThread', {threadId, thread: {...thread, firstPostId: post['.key']}})
        })
      resolve(state.threads[threadId])
    },
        updateThread ({state, commit, dispatch}, {title, text, id}) {
              return new Promise((resolve, reject) => {
                    const thread = state.threads[id]
                    const newThread = {...thread, title}
                    commit('setThread', {thread: newThread, threadId: id})

这里还有一个错误^(更新线程行),要求在结束括号之后和左方括号之前有一个逗号

代码语言:javascript
复制
                dispatch('updatePost', {id: thread.firstPostId, text})
                          .then(() => {
                              resolve(newThread)
                            })
                  })
        }
      updatePost ({state, commit}, {id, text}); {
              return new Promise((resolve, reject) => {
                    const post = state.posts[id]
                    commit('setPost', {postId: id, post: {...post, text}})
                    resolve(post)
                  })
              }
      updateUser ({commit}, user);{
      commit('setUser', {userId: user['.key'], user})
    }},
  setThread (state, {thread, threadId}) {
    Vue.set(state.threads, threadId, thread)
  },

  mutations: {
    setPost (state, {post, postId}) {
      Vue.set(state.posts, postId, post)
    },
    setUser (state, {user, userId}) {
      Vue.set(state.users, userId, user)
    },
    AppendPostToThread (state, {postId, threadId}) {
      const thread = state.threads[threadId]
      if (!thread.posts) {
        Vue.set(thread, 'posts', {})
      }
      Vue.set(thread.posts, postId, postId)
    },
    appendPostToUser (state, {postId, userId}) {
      const user = state.users[userId]
      if (!user.posts) {
        Vue.set(user, 'posts', {})
      }
      Vue.set(user.posts, postId, postId)
    },
    appendThreadToForum (state, {forumId, threadId}) {
      const forum = state.forums[forumId]
      if (!forum.threads) {
        Vue.set(forum, 'threads', {})
      }
      Vue.set(forum.threads, threadId, threadId)
    },

    appendThreadToUser (state, {userId, threadId}) {
      const user = state.users[userId]
      if (!user.threads) {
        Vue.set(user, 'threads', {})
      }
      Vue.set(user.threads, threadId, threadId)
    }
    }
})

问题是上面的最后一个圆括号^,它说应该有一个逗号。

EN

回答 1

Stack Overflow用户

发布于 2018-07-02 05:27:43

在操作之前,您缺少getter的右括号。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51124508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档