1. 程式人生 > >axios傳送post請求,thinkphp獲取不到引數

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();獲取到的是引數陣列。