Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"pinia": "^2.1.7", has bug,click button more time, the arr disaplay wrong. #2687

Closed
sikerxu opened this issue Jun 8, 2024 · 1 comment
Closed

Comments

@sikerxu
Copy link

sikerxu commented Jun 8, 2024

Reproduction

this.arr.length in store index , one time right, more time wrong

Steps to reproduce the bug

import { defineStore } from "pinia";

export const useMainStore = defineStore('main',{

state:()=>{
return {
count:100,
foo:'foo',
arr:[1,2,3],
}
},

// 类似于组件的 computed,用来封装计算属性,有缓存的功能
getters:{

},

// 类似组件的 methods 封装业务逻辑,修改state
actions:{
gai(num){
this.count+=num;
this.foo=this.foo + num;
this.arr.push(this.arr.length + num); // 有 BUG
}
}
})

App.vue

{{ mainStore.arr }}
{{ foo }}
{{count }}
<button @click="patch_action">通过action改</button>
<script setup> import {useMainStore} from './store'; import {storeToRefs} from 'pinia'; const mainStore = useMainStore(); // 解构使用,并使用 storeToRefs 让其变成响应式 const {count,foo}= storeToRefs(mainStore); // 修改数据方式4:通过定义在 Store 中的 action 函数修改 function patch_action(){ mainStore.gai(5); } </script>

Expected behavior


click the button 3 times, result is [ 1, 2, 3, 8, 9, 10, 11, 12 ]

Actual behavior


click the button 3 times, result is [ 1, 2, 3, 8, 9, 10, 11, 12 ]

Additional information

No response

Copy link
Member

posva commented Jun 8, 2024

Open a properly formatted markdown discussion in the help section and you will likely receive help 🙂

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants