简体   繁体   中英

Why doesn't re-render Vue the component after changing the Pinia state (deleteing an object in Array)?

I have a deleteHandler function, which changes the users array in pinia. However, in the devtools in vue, the state is changed, but the component didn't re-render, but if I instead deleting the object from the array, just change some values, then vue recognize it and re-render the component, only by deleting the object from the array doesn't work.

const deleteHandler = (user) => {
  //doesn't renders
    useUser.users = useUser.users.filter(usr => usr.id !== user.id) 
  //it works, the component is re-rendered
  useUser.users.forEach(usr => {
    usr.points += 1
  })
}

I thinks it some kind of reference issue. Please try this one

useUser.users = [...useUser.users.filter(usr => usr.id !== user.id)];

insted of

useUser.users = useUser.users.filter(usr => usr.id !== user.id) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM