Created
September 1, 2021 11:49
-
-
Save dosandk/2d4316e98cd29aab22a1eb48140ccf29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
| <meta charset="UTF-8"> | |
| <body></body> | |
| <div id="root"></div> | |
| <script> | |
| class Component { | |
| json; | |
| constructor(data = []) { | |
| this.data = data; | |
| this.getData() | |
| .then(() => { | |
| this.update(); | |
| }); | |
| this.render(); | |
| } | |
| getData () { | |
| return fetch('https://jsonplaceholder.typicode.com/todos/1') | |
| .then(response => response.json()) | |
| .then(json => { | |
| this.json = json; | |
| }) | |
| } | |
| update () { | |
| const pre = this.element.querySelector('pre'); | |
| pre.innerHTML = JSON.stringify(this.json, null, 2); | |
| } | |
| render () { | |
| const element = document.createElement('div'); | |
| element.innerHTML = ` | |
| <h1>Hello, <span style="color: green">World!</span> | |
| <pre> | |
| </pre> | |
| </h1> | |
| `; | |
| this.element = element; | |
| } | |
| } | |
| const obj = new Component(); | |
| root.append(obj.element); | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment