axios发送post请求,thinkphp获取不到参数

我使用的是vue-cli

可能是发送的数据格式不对,需要添加头信息(content-type)。引入qs插件,用qs转变数据格式。

import qs from 'qs';

axios.post('/api/xxx/xxx/xxx?'+qs.stringify(newChild),
                    {
                        headers:{
                            "Content-Type":'application/x-www-form-urlencoded;charset=UTF-8'
                        }
                }).then(res=>{
                    console.log(res);
                }).catch(err=>{
                    console.log(err);
                })

服务器端:引入use think\Request;使用$arr = Request::instance()->param();获取到的是参数数组。

猜你喜欢

转载自blog.csdn.net/qq_33518543/article/details/83412607
今日推荐