Mitrhril request...
artydev
Posted on July 13, 2020
Using Mithril is just using Javascript.
I continuously look other awesome libraries like Sinuous, Solid, Surplus, Hyperapp, Svelte, but I can't leave Mithril for those :-)
let app = document.getElementById("app");
const urlapi = "https://randomuser.me/api/?results=10";
let Titre = m("div.w3-white.cust-div-titre.w3-padding", "Users");
const cardUserCss = "div.w3-panel.w3-card.w3-teal.cust-div-user";
const imgUserCss = "img.cust-img-user";
const spanUserCss = "span.cust-span-user";
const listContainer = "div.cust-div-container";
let User = function () {
return {
view: ({ attrs: { user } }) =>
m(
cardUserCss,
m("p", [
m(imgUserCss, { src: user.picture.medium }),
m(spanUserCss, user.name.first),
m(spanUserCss, user.name.last),
])
),
};
};
let users = [];
let createListUsers = (user) => m(User, { user });
let App = function () {
return {
oninit: m.request({ url: urlapi }).then(function (data) {
users = data.results;
}),
view: () => [
Titre,
(users && m(listContainer, users.map(createListUsers))) || "Loading....",
],
};
};
m.mount(app, App);
You can test it here : Users
💖 💪 🙅 🚩
artydev
Posted on July 13, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
watercooler Why does a reboot make your PC run SO much faster than running all the cleaning tools you can possibly imagine?
November 30, 2024