首页 > 解决方案 > vue:错误:解析错误:意外的令牌

问题描述

错误:解析错误:意外的令牌

我收到了这个错误:

解析错误-chrome

解析错误-vscode

但是,错误显示: 预期的','

 const fetchUsers (context, userId) => {
      try {
        const response = await axios.post('/', {
          query: getUsers,
          variables: {
            id: userId
          } 
        })
        console.log('RESP POST:', response.data.data)
        console.log(response.data.data.userById)
        return response
      } catch (error) {
        console.log(error)
      }
    }

标签: javascriptvue.js

解决方案


您缺少 function 关键字:

async function fetchUsers (context, userId) {
  // body of function here
}

或者,您可以使用粗箭头语法:

const fetchUsers = async (context, userId) => {
  // body of function here.
}

推荐阅读