No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    reset state in vuex

    Help
    2
    5
    812
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      ael last edited by

      Hey Community!
      my action :

      export function addItem({  commit,dispatch}, item) {
        return new Promise((resolve, reject) => {
          http
            .post(_api.SAVE_item, item)
            .then((response) => {
              resolve(response)
            })
            .catch((error) => {
              let errorsMsg = _get(error, 'response.data.fieldErrors')
              commit('errors', errorsMsg)
              reject(error)
            })
        })
      }
      

      i use this action in two form :save item and update item ,

      and I get errors by my getter in computed property :

       ...mapGetters("item", ["errors"])
      

      my issue is if errors contain a value after using save form , when I open update form it’s still show me the same value of errors .
      What I need is to reset the value of errors each time I change the form .

      any help !!

      Thanks in advance 😁

      1 Reply Last reply Reply Quote 0
      • syflex
        syflex last edited by syflex

        Create a mutation that call the state object (errors) and reinitialise it to null or " " .

        Then commit the mutation on created hook of save and update form page.

        I will write you the code if you still don’t get it.

        A 1 Reply Last reply Reply Quote 0
        • A
          ael @syflex last edited by

          @syflex do you mean to create another mutation ?? because normaly i have already this one where I commit the value of errors generated after catch :

          export const errors = (state, errors) => {
            state.errors = errors
          }
          

          and this is my getter:

          export const errors = (state) => {
            return state.errors
          }
          

          and here is my state:

          errors: {}
          
          1 Reply Last reply Reply Quote 0
          • syflex
            syflex last edited by

            export const clear_errors = (state, errors) => {
            state.errors = β€œβ€
            }

            is the quickest way to go and just commit it when you need to clear state.errors

            A 1 Reply Last reply Reply Quote 1
            • A
              ael @syflex last edited by

              Thanks that works πŸ‘

              1 Reply Last reply Reply Quote 0
              • First post
                Last post