class Filter {
constructor() {
this.init();
}
async init() {
try {
const response = await fetch('http://validity.local/wp-json/wp/v2/posts');
const posts = await response.json();
this.renderPosts(posts);
} catch (error) {
console.error('Error fetching posts:', error);
}
}
renderPosts(posts) {
const outputDiv = document.getElementById('filter-output');
outputDiv.innerHTML = '';
posts.forEach((post) => {
const postTitle = document.createElement('h2');
postTitle.innerHTML = post.title.rendered;
outputDiv.appendChild(postTitle);
});
}
}
export default Filter;
Leave a Reply