Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

663
Views
(¿Por qué) .forEach() muta el estado de vuex?

Tomo dos conjuntos de saldos de mi estado vuex y los combino en una nueva matriz de entradas. ¿Por qué aparece un error cuando itero sobre mis copias del estado vuex? ¿Me estoy perdiendo de algo?

.filter() devuelve una nueva matriz, por lo que las coins ya no están conectadas al $estado.

No estoy mutando el estado vuex, sino mis copias. Todavía me advierten que no mute la tienda vuex fuera de las mutaciones.

esto tendría sentido, si esas asignaciones fueran referencias reales a la tienda vuex, pero no lo son (¿o lo son?). He tratado de entender qué está mal aquí, pero no puedo entender qué está mal aquí. Espero muchachos que puedan ayudar. ¡Gracias!

 filteredItems() { let coins = this.$store.state.wallet.balances.filter(( item ) => this.getCoinPropertiesByTicker(item.ticker).staking_available); const stakingCoins = this.$store.state.wallet.stakingBalances; -> coins.forEach((coin) => { // error happening here const stakingCoin = stakingCoins.user.stats.find((name) => name.ticker === coin.ticker) if (stakingCoin) { coin.totalAmount = { amt: new BigNumber(stakingCoin.balance).decimalPlaces(8).toString(), usd: new BigNumber(stakingCoin.balance_usd).decimalPlaces(2).toString() } } return coins } [Vue warn]: Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] do not mutate vuex store state outside mutation handlers." (found in <Root>) vue.esm.js?a026:1897 Error: [vuex] do not mutate vuex store state outside mutation handlers. at assert (vuex.esm.js?2f62:90) at Vue.store._vm.$watch.deep (vuex.esm.js?2f62:793) at Watcher.run (vue.esm.js?a026:4577) at Watcher.update (vue.esm.js?a026:4551) at Dep.notify (vue.esm.js?a026:739) at Object.reactiveSetter [as amountStaked30] (vue.esm.js?a026:1064) at eval (Staking.vue?3a4a:134) at Array.forEach (<anonymous>) at VueComponent.filteredItems (Staking.vue?3a4a:115) at Watcher.get (vue.esm.js?a026:4488)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como otros han publicado (y no lo sabía), los elementos reales dentro de la matriz son referencias a la tienda, incluso después de asignarlos a una variable.

en mi caso, hice JSON.parse(JSON.stringify(this.$store.state.wallet.balances)).filter(( item ) => this.getCoinPropertiesByTicker(item.ticker).staking_available) , lo que crea una profunda copiar, y ahora el error se ha ido.

¡Gracias!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!