Vue multiple dynamic likes (child component modifies parent component value)

there is a dynamic article array posts_list. Each item in the array has a like status and a number of likes. I need to package likes separately, and I will change the status and quantity when giving likes. Child components cannot directly modify the value of the parent component, and it can be troublesome to publish subscriptions with custom events. I need to know which item in the array to like, and then modify it in the parent component. Is there any other better way?

May.12,2022

  • parent component passes in id ( props )
  • After the

    child component triggers the like event ( @ click ), activate an event for the parent component:

      

    do not want to use the method of passing values between components, you can use vuex, the status and number of likes are all put in the state, no matter which component you modify, state is dynamic.

Menu