提交 57ee2f06 编写于 作者: yma16's avatar yma16

fix:添加超时loading

上级 c437a5f5
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
type="primary" type="primary"
style="margin-left: 5px" style="margin-left: 5px"
@click="increment(userId, articleId, articleCommit)" @click="increment(userId, articleId, articleCommit)"
v-loading="submitLoading"
>提交评论</el-button >提交评论</el-button
> >
</div> </div>
...@@ -43,6 +44,7 @@ export default { ...@@ -43,6 +44,7 @@ export default {
// props定义则data()无需定义 // props定义则data()无需定义
data() { data() {
return { return {
submitLoading: false,
noneMsg: "还没人评论>_<", noneMsg: "还没人评论>_<",
msg: "评论区", msg: "评论区",
baseurl: "/api/", baseurl: "/api/",
...@@ -58,7 +60,7 @@ export default { ...@@ -58,7 +60,7 @@ export default {
watch: { watch: {
articleId: function (newData) { articleId: function (newData) {
this.childArticleId = newData; this.childArticleId = newData;
return newData return newData;
}, },
}, },
mounted() { mounted() {
...@@ -100,7 +102,7 @@ export default { ...@@ -100,7 +102,7 @@ export default {
getComments(articleId) { getComments(articleId) {
let that = this; let that = this;
let params = { let params = {
articleId: articleId ? articleId : that.articleId, articleId: articleId || that.articleId,
}; };
axios axios
.post(that.baseurl + "comment/get/", params) .post(that.baseurl + "comment/get/", params)
...@@ -138,6 +140,7 @@ export default { ...@@ -138,6 +140,7 @@ export default {
}); });
return false; return false;
} }
that.submitLoading = true;
const userInfo = JSON.parse(localStorage.getItem("yma16siteUserInfo")); const userInfo = JSON.parse(localStorage.getItem("yma16siteUserInfo"));
that.userId = userInfo.username; that.userId = userInfo.username;
let params = { let params = {
...@@ -148,6 +151,7 @@ export default { ...@@ -148,6 +151,7 @@ export default {
axios axios
.post(that.baseurl + "comment/post/", params) .post(that.baseurl + "comment/post/", params)
.then((res) => { .then((res) => {
that.submitLoading = false;
that.articleCommit = null; that.articleCommit = null;
try { try {
let resData = res.data; let resData = res.data;
...@@ -156,10 +160,12 @@ export default { ...@@ -156,10 +160,12 @@ export default {
item.date = that.dateToString(item.date); item.date = that.dateToString(item.date);
}); });
} catch (e) { } catch (e) {
that.submitLoading = false;
throw Error(e); throw Error(e);
} }
}) })
.catch((r) => { .catch((r) => {
that.submitLoading = false;
that.$router that.$router
.push({ .push({
path: "/login", path: "/login",
......
<template> <template>
<div class="login" style="text-align: center"> <div class="login" style="text-align: center">
<el-card class="box-card" style="text-align: center"> <el-card class="box-card" style="text-align: center" v-loading="loading">
<el-form <el-form
:model="ruleForm" :model="ruleForm"
status-icon status-icon
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
style="text-align: center; margin: 0 auto" style="text-align: center; margin: 0 auto"
> >
<el-form-item><p style="font-size: 30px">登录</p></el-form-item> <el-form-item><p style="font-size: 30px">登录</p></el-form-item>
<el-form-item label="账号" prop="name"> <el-form-item label="账号" prop="name">
<el-input v-model="ruleForm.name"></el-input> <el-input v-model="ruleForm.name"></el-input>
</el-form-item> </el-form-item>
...@@ -83,6 +82,7 @@ export default { ...@@ -83,6 +82,7 @@ export default {
// } // }
// }; // };
return { return {
loading: false,
// baseurl:"http://127.0.0.1/user/login/", // baseurl:"http://127.0.0.1/user/login/",
baseurl: "/api/", baseurl: "/api/",
// baseurl: 'http://yongma16.xyz/user/login/', // baseurl: 'http://yongma16.xyz/user/login/',
...@@ -103,6 +103,7 @@ export default { ...@@ -103,6 +103,7 @@ export default {
const that = this; // this指向 const that = this; // this指向
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
that.loading = true;
// 提交数据 // 提交数据
const loginUrl = that.baseurl + "user/login/"; const loginUrl = that.baseurl + "user/login/";
const userInfo = { const userInfo = {
...@@ -129,8 +130,10 @@ export default { ...@@ -129,8 +130,10 @@ export default {
// alter("失败!" res.data.msg) // alter("失败!" res.data.msg)
that.$message.error("用户名或密码错误"); that.$message.error("用户名或密码错误");
} }
that.loading = false;
}) })
.catch((error) => { .catch((error) => {
that.loading = false;
that.$message.error(error); that.$message.error(error);
}); });
} else { } else {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
label-width="100px" label-width="100px"
class="demo-ruleForm" class="demo-ruleForm"
style="text-align: center; margin: 0 auto" style="text-align: center; margin: 0 auto"
v-loading="loading"
> >
<el-form-item> <el-form-item>
<!-- 弹出一个警告框 --> <!-- 弹出一个警告框 -->
...@@ -115,6 +116,7 @@ export default { ...@@ -115,6 +116,7 @@ export default {
} }
}; };
return { return {
loading:false,
register_success: false, register_success: false,
register_error: false, register_error: false,
// baseurl: "http://127.0.0.1/", // baseurl: "http://127.0.0.1/",
...@@ -137,6 +139,7 @@ export default { ...@@ -137,6 +139,7 @@ export default {
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
const that = this; const that = this;
if (valid) { if (valid) {
that.loading=false
// 提交数据 // 提交数据
// alert("yes submit!"); // alert("yes submit!");
that.register_success = false; // 初始化register的状态 that.register_success = false; // 初始化register的状态
...@@ -162,9 +165,11 @@ export default { ...@@ -162,9 +165,11 @@ export default {
type: "success", type: "success",
}); });
} }
that.loading=false
}) })
.catch(function (res) { .catch(function (res) {
// 获取res中的name // 获取res中的name
that.loading=false
that.$message({ that.$message({
message: "注册失败" + that.ruleForm.name + "!", message: "注册失败" + that.ruleForm.name + "!",
type: "error", type: "error",
......
...@@ -86,7 +86,7 @@ export default { ...@@ -86,7 +86,7 @@ export default {
{ {
type: "string", type: "string",
required: true, required: true,
message: "不能为空", message: "不能为空",
trigger: "blur", trigger: "blur",
}, },
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册