-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-ajax.html
71 lines (58 loc) · 1.47 KB
/
index-ajax.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Probando dile-ajax</title>
</head>
<body>
<my-app></my-app>
<script type="module">
import { LitElement, html } from 'lit';
import '@dile/crud/components/ajax/ajax.js';
class MyApp extends LitElement {
firstUpdated() {
const ajaxComponent = this.shadowRoot.getElementById('ajaxComponent');
ajaxComponent.generateRequest();
}
static get properties() {
return {
todos: { type: Array }
};
}
constructor() {
super();
this.todos = [];
}
render() {
return html`
<dile-ajax
id="ajaxComponent"
method="get"
url="https://jsonplaceholder.typicode.com/posts"
@ajax-success=${this.handleSuccess}
@ajax-error=${this.handleErrors}
></dile-ajax>
<ul>
${this.todos.map(todo => html`
<li>
<b>${todo.id}</b>:
${todo.title}
</li>
`)}
`
}
handleSuccess(event) {
const data = event.detail;
console.log('Datos recibidos:', data);
this.todos = event.detail;
}
handleErrors(event) {
const error = event.detail;
console.error('Error en la solicitud:', error);
}
}
customElements.define('my-app', MyApp);
</script>
</body>
</html>