Ajax
Where do I make an AJAX request to retrieve data?
Inside the mounted() life cycle hook.
import { Component } from "combo-js";
const Example = new class Component {
created() {
this.data = {
items: []
}
}
mounted() {
fetch("example.json")
.then((resp) => {
return this.json();
})
.then((json) => {
this.update({
items: json
});
});
}
_items() {
return this.data.items.map((item) => {
return `
<li>${item}</li>
`;
}).join("");
}
render() {
return `
<ul>
${this._items()}
</ul>
`;
}
}();
Last updated