Int_Prog/лаб3/lab3/public/scripts/item.js
2024-01-19 01:24:45 +04:00

19 lines
529 B
JavaScript

import { getParamId } from "./helpers/getParamId.js";
import { fetchProductById } from "./api/fetchProductById.js";
import { getItemHTML } from "./helpers/getItemHTML.js";
import { itemContainer } from "./variables.js";
if (itemContainer) drawProduct();
async function drawProduct() {
const productId = getParamId();
if (!productId) return alert("Ошибка!");
try {
const data = await fetchProductById(productId);
itemContainer.innerHTML = getItemHTML(data[0]);
} catch (err) {
console.log(err);
}
}