Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
fix(question): 发布问题时增加重复提交拦截
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Sep 26, 2018
1 parent 2fabc30 commit 385f722
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./style/tsplus.less";
import "github-markdown-css";
import Vue from "vue";
import "./util/rem";
import "./util/prototype"; // 原型拓展

import Modal from "./plugins/modal/";
// import imgLazy from "./plugins/imgLazy";
Expand Down
6 changes: 6 additions & 0 deletions src/page/post/PostQuestion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default {
data() {
return {
step: 1,
loading: false,
topics: [],
questions: [],
Expand Down Expand Up @@ -297,6 +298,8 @@ export default {
});
},
postQuestion(params) {
if (this.loading) return;
this.loading = true;
// POST /questions
this.$http
.post(`/questions`, params, {
Expand All @@ -306,6 +309,9 @@ export default {
this.$Message.success(message);
this.$router.push(`/questions/${question.id}`);
this.$lstore.removeData("H5_POST_QUESTION_DRAFT");
})
.finally(() => {
this.loading = false;
});
},
cancel() {
Expand Down
13 changes: 13 additions & 0 deletions src/util/prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 补充 ES6 新提案 Promise.prototype.finally 在 iOS 下不生效的问题
if (typeof Promise.prototype.finally !== "function") {
Promise.prototype.finally = function(callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason =>
P.resolve(callback()).then(() => {
throw reason;
})
);
};
}

0 comments on commit 385f722

Please sign in to comment.