vue 小 demo 的 post 请求被挂起怎么办?

2019-02-20 21:29:39 +08:00
 supuwoerc
如题 自己写的烂代码,之前一直没问题,最近打开想加一点功能发现跑都跑不起来了,在网页的 Network 看见请求被挂起:Provisional headers are shown,之前遇到过一次过会不知道怎么就好了,没怎么在意,网上看见的解决方法都不好使,因为是本地项目,都是 http 请求,不是网上说的安全降级问题,而且不只是谷歌浏览器,所以不是浏览器问题,这次想不到原因的再次出现,问问大家这怎么解决。
也不知道怎么了,貌似是对象传过去解析不出来的原因,但是之前还能跑,咋回事啊。。。

注:前端的提交代码
` this.$http.post('saveuser',
{
uname: this.$refs.uname.value,
upassword: this.$refs.upassword.value,
email: this.$refs.email.value,
problem: this.$refs.problem.value,
answer: this.$refs.answer.value
}).then(function (res) {
if (res.body.code == 1) {
this.registerOk = true;
this.registerMsg = "注册成功";
setTimeout(function () {
this.$router.push({path: '/index'});
}.bind(this), 1500);

} else {
this.registerOk = true;
this.registerMsg = res.body.msg;
}
}.bind(this))`


注:后端的 node 代码
`exports.saveUser = function (req, res) {
console.log("这里是 saveuser 方法");
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
if (fields.email) {
user.find({
email: fields.email
}, function (err, data) {
// 新用户数据存入数据库
if (data.length == 0) {
user.insertUser(fields, function (result) {
console.log("数据处理完成,code=" + result);
res.json({
"code": result
});
});
}
//数据库查出来存在这个用户了 返回已经注册的信息
else {
res.json({msg: "该邮箱已注册"});
}
});
}
});
};`
3287 次点击
所在节点    Node.js
2 条回复
qilishasha
2019-02-21 10:49:50 +08:00
setTimeout 中不用箭头,现在直接可以用 this 了吗??
supuwoerc
2019-02-21 18:57:46 +08:00
@qilishasha 额,我用 bind 修改了 this 指向啊。。 而且和箭头函数没关系啊,箭头函数也可以修改指向的啊。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/537037

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX