vue中axios使用post提交传递的参数不是key value的格式

vue中axios后台接收的传递参数是key value的格式,但是使用axion传递的参数却是json格式的数据,所以一直请求失败
解决传递key  value 的问题
 





这时候传递过去的是json格式的数据
var param = {
                    'userName':this.formLogin.username,'passWord':this.formLogin.password
                }

                axios({
                    method: 'post',
                    url: 'http://localhost:8083/cyi-data/admin/user/login',
                    data:param
                }) .then(function (response) {
                    console.log(response);
                }) .catch(function (error) {
                        console.log(error);
                        console.log("错误");
                    });

这个时候需要传递key value的数据
导入 qs;
import qs from 'qs';

然后data 使用data:qs.stringify(param)

var param = {
                    'userName':this.formLogin.username,'passWord':this.formLogin.password
                }

                axios({
                    method: 'post',
                    url: 'http://localhost:8083/cyi-data/admin/user/login',
                    data:qs.stringify(param)
                }) .then(function (response) {
                    console.log(response);
                }) .catch(function (error) {
                        console.log(error);
                        console.log("错误");
                    });


image.png
image.png
image.png
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容