我已经在这个问题上工作了大约三个小时,但我找不到我做错了什么或如何解决。我已经检查了堆栈,却没有找到任何东西,而且我不确定这是否是语法,还是我在编程中做了与语法无关的严重错误(逻辑错误等)。我对JS和stackoverflow都是陌生的,因此,如果我的格式,询问此问题的方式或一般的问题不正确,我深表歉意。
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})
这里也有一个错误^(更新线程行),期望在右括号后和右括号之前有一个逗号
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)
}
}
})
问题在于上面的最后一个括号^,它表示期望逗号。
答案 0 :(得分:0)
在采取行动之前,您缺少吸气剂的右括号。