美文网首页
vue中axios使用post提交传递的参数不是key valu

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

作者: 山水风情 | 来源:发表于2017-09-06 19:08 被阅读0次
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

相关文章

网友评论

      本文标题:vue中axios使用post提交传递的参数不是key valu

      本文链接:https://www.haomeiwen.com/subject/empvjxtx.html