axios 에서 get 방식 params 보낼 때는 { Params : { userId: 1 } } 같이 params 키를 사용하자.
axios 에서 아래와 같이 보내면 nodejs 에서 req.userId 로 받지 못함.
에러
axios.get('/api/place', {userId: 1}).then(data=>{
console.info('data', data.data)
}).catch(err=>{})
아래와 같이 'params' key를 가진 Object로 전달하면 Nodejs 에서 받을 수 있음.
성공
axios.get('/api/place', {params: {userId: 1}}).then(data=>{
console.info('data', data.data)
}).catch(err=>{})
Nodejs에서는 아래처럼 값을 접근할 수 있음.
NodeJs
router.get('/place', (req, res, next)=>{
console.info('req.query.userId : ', req.query.userId)
}