0

i already call the axios and show using console log if it is successful or not already, However i wanted to pass the axios post response value to my vue component and display the response in my vue component in order for me to make a condition. Is there any way to do it? I try some other part but no luck. Kindly guide me.

main.vue

  methods: {
    onClicked() {
      this.$store
        .dispatch('Clickme', this.data)
        .then(() => {
          alert("Success");
        })
        .catch(() => {
          alert("Error");
        })
    }
  }

clicked.js

        return new Promise((resolve, reject) => {
            clicked(username, password)
                .then(resp => {
                    console.log("---->>>> : ");
                    const data = resp.data.data
                    console.log(username, password);
                    console.log(resp);
                    console.log("statresponse.status : " + resp.data.status);
                    console.log("statresponse.message : " + resp.data.message);

                    console.log("statresponse.inside message : " + resp.data.data.message);
                    // console.log("USER.JS RESPONSE: " + resp.data.status);
                    // console.log("USER.JS RESPONSE: " + resp.data.message);

                    setToken(data.token)
                    commit('SET_TOKEN', data.token)

                    resolve()
                })
                .catch(error => {
                    console.log(error)
                    reject(error)
                })
        })

1 Answer 1

1

Try changing main.vue to:

 onClicked() {
      this.$store
        .dispatch('Clickme', this.data)
        .then((response) => {
          //Do whatever you want with your response
          alert("Success");
        })
        .catch(() => {
          alert("Error");
        })
    }

and change clicked.js to:

 resolve(resp.data.data)

This will make so the promise resolves the response data.

However if you make the http request in your store/using vuex, what you probably want to do is commit a mutation to put the response into your state - and then map the state from your component.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank youuuuu!! i try that its working. Thank you very muchhhh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.