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);
}
);
}
}
vue中this.$http.post()跨域和请求参数丢失解决方案
最新推荐文章于 2026-06-21 09:56:28 发布
博客展示了在Vue中使用$http.post请求远程资源的代码。通过指定请求的URL、参数,还解决了跨域问题。成功请求后会打印响应信息,失败则打印状态码。

692

被折叠的 条评论
为什么被折叠?



