小编Shu*_*ade的帖子

React JS 意外的保留字“await”

我正在努力解决这个异步等待问题我已经创建了异步函数,为此我正在调用等待但我收到错误意外的保留字“等待” 下面是异步函数

export const addProductCall = async (product) => {
    let accessToken = window.localStorage.getItem("accessToken");
    await axios.post(SERVER_URI + '/inventoryservice/v1/item',
        product,
        { headers: { "Authorization": "Bearer " + accessToken, "Content-Type": "application/json" } })
}
Run Code Online (Sandbox Code Playgroud)

下面是我调用该函数的函数。

const handleSubmit = () => {
        const data = {
            'storeId': customerDetails.id, category, categoryToBeAdded, description,
            productCode, productName, sku, price, unit, quantity
        }
        await addProductCall(data);
    }
Run Code Online (Sandbox Code Playgroud)

javascript async-await

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

async-await ×1

javascript ×1