Képek és Tailwind
This commit is contained in:
1 parent
15ced67b41
commit
464230982d
3 files changed
+74
-5
No files matched your search
+31
-5
@@ -13,13 +13,39 @@ keres.onload=function(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keres.send();
|
//keres.send();
|
||||||
|
|
||||||
|
|
||||||
console.log(valasz);
|
console.log(valasz);
|
||||||
|
|
||||||
fetch('https://jsonplaceholder.typicode.com/posts')
|
//Kérések fajtái: GET, POST, PUT, PATCH, DELETE, OPTIONS
|
||||||
.then(res=>res.json())
|
|
||||||
.then(adat=>console.log(adat))
|
|
||||||
.catch(error=>console.log(error));
|
|
||||||
|
|
||||||
|
// fetch('https://jsonplaceholder.typicode.com/posts')
|
||||||
|
// .then(res=>res.json())
|
||||||
|
// .then(adat=>console.log(adat))
|
||||||
|
// .catch(error=>console.log(error));
|
||||||
|
|
||||||
|
//async await
|
||||||
|
|
||||||
|
async function letolt() {
|
||||||
|
try {
|
||||||
|
let keres=await fetch('https://jsonplaceholder.typicode.com/posts');
|
||||||
|
let valasz=await keres.json();
|
||||||
|
|
||||||
|
console.log(valasz);
|
||||||
|
valasz.forEach(post => {
|
||||||
|
let p=document.createElement('p');
|
||||||
|
let body=document.createElement('p');
|
||||||
|
body.textContent=post.body;
|
||||||
|
p.textContent=post.title;
|
||||||
|
root.appendChild(p);
|
||||||
|
root.appendChild(body);
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
alert(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
letolt();
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="hu">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<script defer src="photos.js"></script>
|
||||||
|
<script defer src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
||||||
|
<title>Képek letöltése</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 class="text-4xl font-bold text-center bg-sky-300 text-sky-800 p-2">Képek letöltése</h1>
|
||||||
|
<div id="root">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
let root=document.getElementById('root');
|
||||||
|
|
||||||
|
let kontener=document.createElement('div');
|
||||||
|
kontener.setAttribute('class','flex flex-row flex-wrap items-center justify-center bg-sky-200');
|
||||||
|
|
||||||
|
fetch('https://jsonplaceholder.typicode.com/photos')
|
||||||
|
.then(res=>res.json())
|
||||||
|
.then(kepek=>{
|
||||||
|
kepek.forEach(kep => {
|
||||||
|
let kepKontener=document.createElement('div');
|
||||||
|
kepKontener.setAttribute('class','flex flex-col items-center justify-center bg-sky-400 m-2 p-2 rounded-xl w-96');
|
||||||
|
let title=document.createElement('p');
|
||||||
|
title.setAttribute('class','text-2xl text-center font-bold text-sky-600');
|
||||||
|
title.textContent=kep.title;
|
||||||
|
|
||||||
|
let image=document.createElement('img');
|
||||||
|
image.setAttribute('class','rounded-xl');
|
||||||
|
image.src=kep.url;
|
||||||
|
kepKontener.appendChild(image);
|
||||||
|
kepKontener.appendChild(title);
|
||||||
|
kontener.appendChild(kepKontener);
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(err=>alert(err));
|
||||||
|
|
||||||
|
root.appendChild(kontener);
|
||||||
Reference in new issue
Block a user