1

I need to set my JSON to variable because I am using it in 2 places, the

let data = {
         "test": "hello",
         "test2": "hello2
    }
    axios.post('/route', {
       data
    })
    .then((response) => {
        this.$emit('anotherFunction', data);
    })

I get a 400 back and then when I inspect the network request, the payload is: "{data: {"test": "hello", "test2": "hello2"}}" which makes sense but how can I have the JSON without the data part of it?

1 Answer 1

2

You should pass data like this:

let data = {
         "test": "hello",
         "test2": "hello2
}
axios.post('/route', data)
.then((response) => {
        this.$emit('anotherFunction', data);
})
Sign up to request clarification or add additional context in comments.

1 Comment

ooh I was putting it directly in { } . Thanks !

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.