vue中this.$http.post()跨域和请求参数丢失的解决
更新时间:2022年04月08日 09:33:52 作者:hanq2016
这篇文章主要介绍了vue中this.$http.post()跨域和请求参数丢失的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
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 => {
})以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
vue中this.$refs.name.offsetHeight获取不到值问题
这篇文章主要介绍了vue中this.$refs.name.offsetHeight获取不到值问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-05-05
在 Vue3 中如何使用 styled-components
styled-components 的官方 Vue 版本目前已多年没有更新,而且只支持到 Vue2,那么,在 Vue3 中怎么才能使用到 styled-components 呢,下面给大家介绍在 Vue3 中使用 styled-components的相关知识,感兴趣的朋友跟随小编一起看看吧2024-05-05
详解Vue项目在其他电脑npm run dev运行报错的解决方法
这篇文章主要介绍了详解Vue项目在其他电脑npm run dev运行报错的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-10-10


最新评论