首页 > 解决方案 > 将 res.send 值从 node.js 后端传递给 react.js

问题描述

我正在尝试使用 res.send 从 nodejs 后端传递一个字符串

app.post("/user", (req,res) => {
console.log(req.body.email);
res.send('haha');
});

我想根据前端检索到的字符串值执行一些操作。

axios({ 
        method: 'post', 
        url: '/user', 
        data: { email: this.state.emailFetch } 
        }).then(response => {
            if(response.send == "haha")
            {
                return <Redirect to="/"/> 
            }
        });

我想我在前端的响应处理上搞砸了。任何人都可以指导我吗?

标签: javascriptnode.jsreactjsexpressaxios

解决方案


Try response.datares.send()只是发送响应的功能。您还可以控制台记录整个响应以检查响应值的存储位置。


推荐阅读