![](/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.