Level: beginner • Mithril.js Version: latest
loading m.mount m.redraw m.request
This is an example showing a loading message using the conditional ternary operator while loading external data. In Mithril.js using the ternary operator is one of the ofting seen practices.
Note: You have to click the refresh button in Flems to see the loading message.
Type | Name | URL |
---|---|---|
script | mithril@latest | https://unpkg.com/mithril@latest |
const app = () => {
let result = ''
// m.request('/url').then(res => result = res)
setTimeout(() => {result = 'Woohoo!'; m.redraw()}, 2000)
return {
view: () =>
!result
? m('div', 'Loading...')
: m('div', result)
}
}
m.mount(document.body, app)
The snippet is using the most current version of Mithril.js framework. It is aimed at beginners and shows some basic recipes.
Besides Mithril.js' hyperscript function m() we can see different Mithril.js API methods like m.request
, m.mount
or m.redraw
.
The example was contributed by osban and last modified on 24 September 2020. Click here to see more examples contributed by the author.
If anyone has some improvements, that should be addressed, let me know by opening an issue. Or simply fork the repository on GitHub, push your commits and send a pull request. For starting your work, you can click the edit link below. Thanks for contributing.