This is a next.js handler function for dealing with api requests on our server i need to access a variable between request methods any help will be muchly appreciated.
export default function handler(req, res) {
if(req.method === 'POST') {
var hi = req.body
}
if (req.method === 'GET') {
console.log(hi)
}
}
Just define it outside the if statements like this:
export default function handler(req, res) {
var hi = req.body
if(req.method === 'POST') {
console.log(hi)
}
if (req.method === 'GET') {
console.log(hi)
}
}
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.