Last active
January 25, 2019 10:31
-
-
Save buddies2705/71e0a2aa635c2da5039f614c4c9c62d1 to your computer and use it in GitHub Desktop.
MithrilJs tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html > | |
<html> | |
<body> | |
<script src = "https://unpkg.com/mithril/mithril.js" > < /script> | |
<script > | |
var root = document.body | |
var count = 0 | |
var increment = function() { | |
m.request({ | |
method: "PUT", | |
url: "//rem-rest-api.herokuapp.com/api/tutorial/1", | |
data: { | |
count: count + 1 | |
}, | |
withCredentials: true, | |
}) | |
.then(function(data) { | |
count = parseInt(data.count) | |
}) | |
} | |
var Hello = { | |
view: function() { | |
return m("main", [ | |
m("h1", { | |
class: "title" | |
}, "My first app"), | |
m("button", { | |
onclick: increment | |
}, count + " clicks"), | |
]) | |
} | |
} | |
var Splash = { | |
view: function() { | |
return m("a", { | |
href: "#!/hello" | |
}, "Enter!") | |
} | |
} | |
m.route(root, "/splash", { | |
"/splash": Splash, | |
"/hello": Hello, | |
}) | |
// your code goes here! | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment