目录this.$Http.post()跨域和请求参数丢失this.http.post()参数需注意this.$http.post()跨域和请求参数丢失 methods: {
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);
}
);
}
}
第一个参数是url,第二个参数是body,body为object,如果body为空的时候,参数填{};
this.http.post('url' + id, {})
.subscribe(res => {
}, error => {
})
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: vue中this.$http.post()跨域和请求参数丢失的解决
本文链接: https://www.lsjlt.com/news/145312.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0