vue中this.$http.post()跨域和请求参数丢失的解决_vue.js

2022年4月27日09:18:30

this.$http.post()跨域和请求参数丢失

methods: {
    research: function () {
        //post请求远程资源
        this.$http.post(
            //请求的url
            "http://www.hefeixyh.com/login.html",
            //请求参数,不能以get请求方式写:{params: {userName: "root123", passWord: "root123"}}
            {userName: "root123", passWord: "root123"},
            //解决跨域问题,不加无法跨域
            {emulateJSON: true}
        ).then(
            function (res) {
                console.log(res);
                this.msg = res.bodyText;
            },
            function (res) {
                console.log(res.status);
            }
        );
    }
}

this.http.post()参数需注意

第一个参数是url,第二个参数是body,body为object,如果body为空的时候,参数填{};

this.http.post('url' + id, {})

.subscribe(res => {
}, error => {
})
  • 作者:hanq2016  
  • 原文链接:https://blog.csdn.net/hanq2016/article/details/90352049
    更新时间:2022年4月27日09:18:30 ,共 550 字。