G
G
GenesisFTW2021-05-22 22:27:00
Express.js
GenesisFTW, 2021-05-22 22:27:00

How to reactively change the icon of saved posts?

I have page articles when I go to this page, I access
mountedthe store action in the hook, there I access the server and return all the articles as objects inside an array. I then pass this array to component - ContentList where I loop through the articles to component - ContentPreview . In ContentPreview I accept in props [content] and it has a code of how articles and a bookmark icon look like and there is a button with a methodthis.$store.dispatch('all-articles')
v-for

savePost(){
const ides = {post_id: this.content.id, user_id: this.GET_USER.id}
this.$store.dispatch('saveOrDelete', ides)
}
when you click on it, I make a request to the server as described above) and send it to the phpmyadmin database, to the table saved_posts post_id and user_id and return an object or if there is already such a post with this post_id and user_id  thereby saving which post was saved with which user. The problem is that I need to change the icon reactively in component ContentPreview when calling the method if it has been saved, and if it has already been saved, then initially, when you go to page articles , you need to change the icon to the saved one and thus change the icon to another when you click. Tried to describe in detail.
{message: saved, post_id: 50}{message: deleted, post_id:50}
savePost()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aetae, 2021-05-23
@Aetae

async savePost(){
  this.iconStatus = 'loading';
  const ides = {post_id: this.content.id, user_id: this.GET_USER.id};
  const result = await this.$store.dispatch('saveOrDelete', ides).catch(() => ({message: 'error'}));
  this.iconStatus = result.message;
}

?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question