question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Vue2] State as default Action parameters

See original GitHub issue

Steps to reproduce the behavior

https://codesandbox.io/s/fast-river-jmtl3?file=/src/store.js

I was calling this action in a regular js file. Having state as default parameters gives a silent error. Had to debug to find out why the function was not getting called.

async fetchNotifications({page = this.notifications.page, limit = this.notifications.limit}) {
 // fetch
}

Screenshot 2021-05-31 at 16 04 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
posvacommented, May 31, 2021

Ah yeah, this is not related to Pinia, it’s about optional parameters with destructuring. This is the correct version:

setNameFromState({ firstName = this.firstName, lastName = this.lastName } = {}) {
      this.name = firstName + ' ' + lastName;
    },
1reaction
posvacommented, May 31, 2021

I will need a boiled down repro to check further. You can use the demo codesandbox

Read more comments on GitHub >

github_iconTop Results From Across the Web

Actions | Vuex
Action handlers receive a context object which exposes the same set of methods/properties on the store instance, so you can call context. ......
Read more >
Vuex - passing multiple parameters to mutation - Stack Overflow
I am not able to figure out how to send multiple parameters to the vuex mutation via an action. - store - export...
Read more >
How To Manage State in a Vue.js Application with Vuex
These are the default values of firstName and lastName , respectively. Data from the Vuex store displayed in the view. In this step,...
Read more >
How To Pass Data Between Components In Vue.js
Tip: Know the Default Getter Arguments # By default, Vuex getters accept two arguments. state — the state object for our application; getters...
Read more >
Only one parameter works when dispatching actions. #366
I have some actions in my existing code base on the version 1.x of Vuex where I dispatch actions with multiple parameters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found