简体   繁体   中英

Destructuring 'req.body.data' into 'req.body'

I am sending some data from the front end to the back end. I am trying to send data as an object to the back. When it arrives, it is obviously req.body.data , but should land in the backend as req.body . How do I destructure the request, either from the front or the back so that the back only receives req.body

front end

const { user } = await axios.post('http://localhost:3000/auth/signup', {data});

Backend (what I want)

if(req.body.type === 'vendor') {

Right now the backend received (What i dont want)

if(req.body.data.type....)

Your passing data as an object prop. Just pass it directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', data)

You are sending object with data property when sending request to the backend. What you should do is destruct that data object and send its property directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', { ...data });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM