0

How can I use this link and get information in vue.js

http://localhost:2020/rest-password${token}&id=${data._id}

My code is:

const submit = async () => {
    console.log('e');
    try {
        const user = await axios.post(`http://localhost:2020/rest-password${token}&id=${data._id}`,{
            password:password.value
        })
        console.log(user, "sss");
        router.push('/log')

    } catch (e) {
        error.value = e.response
    }
}

I tried to get information from Backend, but I think the method is incorrect

When I put the link in Postman I can get it

http://localhost:2020/rest-password?token=a3224e69cba1be642b97c2ab7265b607ff9d8052c253cbc221cfee80327d&id=6226fa4a2ff1d47fa2e732d7 
tony19
  • 125,647
  • 18
  • 229
  • 307
fahad
  • 11
  • 3
  • Does this answer your question? [How to post query parameters with Axios?](https://stackoverflow.com/questions/53501185/how-to-post-query-parameters-with-axios) – Estus Flask Mar 08 '22 at 08:04

1 Answers1

0

Assuming token contains only the token value (e.g., a322⋯327d), the token is incorrectly appended in the URL string:

const user = await axios.post(`http://localhost:2020/rest-password${token}&id=${data._id}`, {⋯})
                                                                  ^^^^^^^^

For example, if token were abcd and data._id were 1234, the result would be:

const user = await axios.post(`http://localhost:2020/rest-passwordabcd&id=1234`, {⋯})

Notice how the token value has no delimiters in the string, and just appears in the middle. Specifically, it's missing token= before the token value; and the ? separator before the query parameters.

Solution

The string should be formatted like this:

const user = await axios.post(`http://localhost:2020/rest-password?token=${token}&id=${data._id}`, {⋯})
                                                                     

As an aside, rest-password seems to contain a typo, assuming rest should be reset.

tony19
  • 125,647
  • 18
  • 229
  • 307