vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
13.11k stars 1.05k forks source link

Array reassignment in store loses the reactive #2494

Closed likeyoukang closed 11 months ago

likeyoukang commented 11 months ago

Reproduction

https://github.com/vuejs/pinia

Steps to reproduce the bug

我在store中定义了一个数组,const collectPoolList = ref<CollectPoolVo[]>([]); 当我在action中给数组重新赋值后,collectPoolList 会丢失响应式, collectPoolList.value = res.data 而我使用 collectPoolList.value.splice(0, collectPoolList.value.length, ...res.data);则不会丢失响应式 数组所有重新赋值都会丢失响应式,我想问一下这是否算是一个bug.

各个依赖版本 "pinia": "^2.1.7", "pinia-plugin-persistedstate": "^3.2.0", "vant": "^4.4.1", "vue": "^3.3.4", "vue-router": "^4.2.5",

5886cf4e3a4fa25e3f7c0502079ee84

Expected behavior

数组重新赋值响应式不丢失

Actual behavior

数组重新赋值响应式丢失

Additional information

No response

posva commented 11 months ago

Please follow the instructions for bug reports. Namely add a repro using the playground