![](/img/trans.png)
[英]At end of JS function declaration, adding semicolon, why jshint prompt an error
[英]"Missing semicolon" error on Async function declaration
在 Vue 应用程序中,我想将 js 函数分组到一个 js 文件中。 在 getData.js 中,我有以下内容:
import { collection, getDocs } from 'firebase/firestore/lite';
import { db } from "./firebase/index";
import store from "../store/index"
async getProjects () {
const querySnapshot = await getDocs(collection(db, "projects"));
querySnapshot.forEach((doc) => {
let project = doc.data()
project.id = doc.id
store.state.currentProjectList.push(project)
});
}
export { getProjects }
我得到“缺少分号”。 我声明 function 的行出错:async getProjects()。
(我知道这不是将数据添加到商店的方式,但这仅用于测试目的)
谢谢你的帮助!
async getProjects () {
是方法声明语法; 它只允许在 object 或 class 定义中使用。
要创建本地 function,您需要使用 function 声明或箭头 function。
async function getProjects () {
或者
const getProjects = async () => {
(您也可以使用 function 表达式,但这与您所拥有的语法相去甚远)。
上一行的分号也不见了import store from "../store/index"
这不是 JS 错误(但如果你使用的是 linter 而不是,则可能是一个 linting 错误提到那个)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.